$('p i').text((i, text) => i % 3 ? text : 'hello, world!!');
document.querySelectorAll('p i').forEach((n, i) => {
n.textContent = i % 3 ? n.textContent : 'fuck the world';
});
p
общий родитель, то можно и не смотреть на индекс, сразу нужные элементы получить:for (const n of document.querySelectorAll('p:nth-of-type(3n + 1) i')) {
n.innerText = 'fuck everything';
}
if (inputs[el].value == "") el++; if (inputs[el].value.match(/[А-я]/)) {
Construct1.apply(this, arguments);
. <label class="button">
<input type="radio" name="button">
<span>click me</span>
</label>
<label class="button">
<input type="radio" name="button">
<span>click me</span>
</label>
.button input {
display: none;
}
.button input:checked + span {
background: red;
color: white;
}
computed: {
namesFilter() {
const name = this.name_from.toLowerCase();
const names = this.names;
const filterBy = [ 3, 4 ];
return name
? names.filter(n => filterBy.some(i => n.children.item[i].value.toLowerCase().includes(name)))
: names;
},
},
filterBy
свойством компонента, привязать его содержимое через v-model
к, например, чекбоксам, и вот уже пользователь может настраивать фильтрацию по произвольному количеству свойств. arr
.reduce({}){|acc, n| acc.update(n[:books])}
.collect{|k, v| { author: k, book: v[:book] }}
.sort_by{|n| n[:author]}
moment.locale('ru');
document.querySelector('#load').addEventListener('click', function load() {
fetch('https://api.github.com/users/fristyr/repos')
.then(r => r.json())
.then(data => {
const formatIn = 'YYYY-MM-DDTHH:mm:ss';
const formatOut = 'DD MMMM YYYY';
document.querySelector('.repo-wrapp').insertAdjacentHTML('afterbegin', data.map(item => `
<article class="repo">
<a href="${item.html_url}" class="repo__name">${item.name}</a>
<br>
<span class="repo__technology">${item.language}</span>
<span class="repo__update">${moment(item.updated_at, formatIn).format(formatOut)}</span>
</article>`
).join(' '));
});
});
event.currentTarget.getAttribute('имя_атрибута')
onClick={e => props.arrowHandler(e, VALUE)}
если условия задачи поменяются и...
<EditorWithTableOfContents tags={[ 'h1' ]} />
<EditorWithTableOfContents tags={[ 'h2', 'h3' ]} />
const EditorWithTableOfContents = ({ tags }) => {
const [headers, setHeaders] = useState([]);
const editorEl = useRef(null);
const onChange = e => {
setHeaders(Array.from(
e.editor.document.$.querySelectorAll(tags.join(', ')),
n => [ n.tagName, n.innerText ]
));
};
const goToAnchor = e => {
const index = e.target.dataset.index;
const d = editorEl.current.editor.document.$;
d.documentElement.scrollTo({
top: d.querySelectorAll(tags.join(', '))[index].offsetTop,
behavior: 'smooth',
});
};
return (
<div>
<CKEditor
data={initData}
onInstanceReady={onChange}
onChange={onChange}
ref={editorEl}
/>
<h2>Содержание</h2>
{headers.map(([Tag, text], index) => (
<Tag key={index} data-index={index} onClick={goToAnchor}>
{text}
</Tag>
))}
</div>
);
};
<div id="slider"></div>
<div id="value"></div>
const min = 100;
const max = 500;
$('#slider').slider({
min,
max,
value: min + Math.random() * (max - min) | 0,
range: 'min',
animate: 'fast',
slide: (e, ui) => $('#value').html(max - ui.value + min),
});
inputChange = e => {
const index = +e.target.dataset.index;
this.setState({
workers: this.state.workers.map((n, i) => i === index
? { ...n, checked: e.target.checked }
: n
),
});
}
<input
type="checkbox"
data-index={index}
onChange={this.inputChange}
checked={item.checked}
/>
const sum = this.state.workers.reduce((acc, n) => acc + (n.checked ? n.salary : 0), 0);
submitText = (e) => {
this.setState({
text: e.target.value,
});
}
function (response) {
на (response) => {
.axios(...).then(function(response) {
this.info = response.data;
}.bind(this));
const that = this;
axios(...).then(function(response) {
that.info = response.data;
});
methods: {
processResponse({ data }) {
this.info = data;
},
},
mounted() {
axios(...).then(this.processResponse);
},
async mounted() {
try {
this.info = (await axios(...)).data;
} catch (e) {}
},