const container = document.querySelector('.side__nav');
const itemSelector = 'li';
const activeClass = 'is-active';container.addEventListener('click', function(e) {
const item = e.target.closest(itemSelector);
if (item) {
this.querySelector(`${itemSelector}.${activeClass}`)?.classList.remove(activeClass);
item.classList.add(activeClass);
}
});const items = container.querySelectorAll(itemSelector);
const onClick = e => items.forEach(n => n.classList.toggle(activeClass, n === e.currentTarget));
items.forEach(n => n.addEventListener('click', onClick));
const element = document.querySelector(`.js-filter-wrap a[data-filter="${конкретноеЗначение}"]`);
if (element) {
...const element = [...elements].find(n => n.dataset.filter === конкретноеЗначение);
if (element) {
...
Internal methods and internal slots are identified within this specification using names enclosed in double square brackets...
Within this specification a well-known symbol is referred to by using a notation of the form @@name...
Within this specification a reference such as %name% means the intrinsic object...
let displayMessage = ''; doItems.forEach((item, i) => { displayMessage += ` <li class="do__item"> <input type="checkbox" id="do_${i}" ${item.checked ? 'checked': ' '}> <label for="do_${i}" class="${item.checked ? 'checked' : ' '}">${item.message}</label> <button class="remove" id="do_${i}">Delete</button> </li>`; block.innerHTML = displayMessage; });
const insert = (str, index, substr) =>
str.replace(RegExp(`(?<=.{${index}})`), substr);
// или
const insert = (str, index, substr) =>
str.replace(RegExp(`.{${index}}`), `$&${substr}`);
// или
const insert = (str, index, substr) =>
str.length >= index ? str.slice(0, index) + substr + str.slice(index) : str;
<input type="radio" name="method" data-placeholder="hello, world!!">
<input type="radio" name="method" data-placeholder="fuck the world">
<input type="radio" name="method" data-placeholder="fuck everything">const updatePlaceholder = (input, radio) =>
input.placeholder = radio.dataset.placeholder;
// или
// input.setAttribute('placeholder', radio.getAttribute('data-placeholder'));
// input.attributes.placeholder.value = radio.attributes['data-placeholder'].value;document.addEventListener('change', ({ target: t }) => {
if (t.matches('input[name="method"]')) {
updatePlaceholder(t.closest('form').querySelector('[name="wallet"]'), t);
}
});const onChange = ({ target: t }) =>
updatePlaceholder(t.form.elements.wallet, t);
for (const form of document.forms) {
for (const radio of form.elements.method) {
radio.addEventListener('change', onChange);
}
}
$.param($(this).serializeArray().filter(n => +n.value && n.name !== 'mode'))
const buttonOpenSelector = '.project__zoom';
const buttonCloseSelector = '.overlay--close';
const contentSelector = '.overlay--gallery';
const key = 'gallery';
const attr = `data-${key}`;
const activeClass = 'overlay--active';$(document)
.on('click', buttonOpenSelector, function() {
$(`${contentSelector}[${attr}="${$(this).data(key)}"]`).addClass(activeClass);
})
.on('click', buttonCloseSelector, function(){
$(this).closest(contentSelector).removeClass(activeClass);
});document.addEventListener('click', ({ target: t }) => {
t
.closest(buttonCloseSelector)
?.closest(contentSelector)
.classList
.remove(activeClass);
(t = t.closest(buttonOpenSelector)) && document
.querySelector(`${contentSelector}[${attr}="${t.dataset[key]}"]`)
.classList
.add(activeClass);
});
const newValue = '!!!';.const count = arr.reduce((acc, n) => (acc[n] = (acc[n] ?? 0) + 1, acc), {});
const newArr = arr.map(n => count[n] > 1 ? newValue : n);
// или
const newArr = arr.map(function(n) {
return this.get(n) ? newValue : n;
}, arr.reduce((acc, n) => acc.set(n, acc.has(n)), new Map));
// или
const newArr = arr.map((n, i, a) => a.indexOf(n) !== a.lastIndexOf(n) ? newValue : n);arr.forEach(function(n, i, a) {
a[i] = ~-this.get(n) ? newValue : n;
}, arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map));
// или
const duplicates = arr.reduce((acc, n) => (acc[n] = acc.hasOwnProperty(n), acc), {});
arr.splice(0, arr.length, ...arr.map(n => [ n, newValue ][+duplicates[n]]));
// или
Object
.values(arr.reduce((acc, n, i) => ((acc[n] ??= []).push(i), acc), {}))
.forEach(n => n.length > 1 && n.forEach(i => arr[i] = newValue));
$('.payment-innovation .item').css('opacity', 0);
$('.payment-innovation .list-block__head').click(function() {
const $this = $(this);
const $items = $this.closest('.list-block').find('.item');
const visible = $this.toggleClass('visible').hasClass('visible');
const duration = 400;
$items.each((i, n) => $(n)
.delay((visible ? i : $items.length - i - 1) * duration)
.animate({ opacity: +visible }, duration)
);
}).click();
const index = arr.findIndex(n => n.id === newObj.id);
arr[index === -1 ? arr.length : index] = newObj;const obj = arr.find(n => n.id === newObj.id);
if (obj) {
Object.assign(obj, newObj);
} else {
arr.push(newObj);
}
stuff.map(n => `${n.firstName} ${n.lastName}`).sort((a, b) => a.localeCompare(b))