data-country
почему-то на русском - какого чёрта? Надо, чтобы были такими же, как и id
у элементов .tabcontent
.const tabLinks = document.querySelectorAll('.tablinks');
const tabContent = document.querySelectorAll('.tabcontent');
tabLinks.forEach(n => n.addEventListener('click', openTab));
function openTab({ currentTarget: t }) {
const { country } = t.dataset;
tabLinks.forEach(n => n.classList.toggle('active', n === t));
tabContent.forEach(n => n.classList.toggle('active', n.id === country));
// или, к чёрту data-атрибуты и id, можно индексами воспользоваться;
// конечно, в этом случае необходимо, чтобы .tablinks и соответствующие им
// .tabcontent были расположены в одинаковом порядке
const index = Array.prototype.indexOf.call(tabLinks, t);
tabLinks.forEach(n => n.classList.toggle('active', n === t));
tabContent.forEach((n, i) => n.classList.toggle('active', i === index));
}
placemark.events.add('click', () => {
// здесь дёргаете scrollTo или scrollIntoView
});
<button v-for="(n, i) in items" @click="onClick(i)">{{ n }}</button>
methods: {
onClick(index) {
this.items = this.items.slice(0, index + 1);
// или
// this.items.splice(index + 1, this.items.length - index);
},
...
},
const info = new google.maps.InfoWindow();
marker.addListener('click', function() {
info.setContent('сюда засовываете свою информацию');
info.open(map, marker);
});
$('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),
});