const parent = document.querySelector('.xlist');
const className = 'active';
const el = parent.querySelector(`:scope > .${className}`);
const index = el ? [...parent.children].indexOf(el) : -1;
let index = -1;
for (let n = el; n; n = n.previousElementSibling, index++) ;
const index = Array.prototype.findIndex.call(
parent.children,
n => n.classList.contains(className)
);
const { children } = parent;
let index = children.length;
while (index-- && !children[index].matches(`.${className}`));
function fb3cont() { b3Cont.classList.remove("__active"); } document.onclick = function() { if (b3Cont.classList.contains("__active")) { fb3cont()}; }
id="666"
, а data-val="666",
например.document.querySelectorAll('селектор ваших блоков').forEach(n => {
const val = +n.dataset.val;
n.classList.toggle('disable', min > val || val > max);
});
const BASE_VALUE = 100;
document.querySelector('.container').addEventListener('change', e => {
document.querySelector('.total').innerText = Array
.from(e.currentTarget.querySelectorAll('input:checked'))
.reduce((acc, n) => acc + +n.value, BASE_VALUE);
});
tableEl
.querySelectorAll('tbody td')
.forEach(td => Array
.from(td.attributes)
.forEach(attr => td.removeAttribute(attr.name))
);
for (const tbody of tableEl.tBodies) {
for (const tr of tbody.rows) {
for (const { attributes: a } of tr.cells) {
for (let i = a.length; i--;) {
a[i].ownerElement.removeAttribute(a[i].name);
}
}
}
}
onFrame(e, data) {
if (!data.frame) {
data.reverse = !data.reverse;
}
},
const average = arr => arr.reduce((acc, n) => acc + n, 0) / arr.length;
const extractValues = (group, item, key) => item[key].forEach(n => ((group.values[n.id] ||= { id: n.id, name: n.name })[key] ||= []).push(n.value));
const result = Object
.values(arr
.flatMap(n => n.properties.groups)
.reduce((acc, n) => (
acc[n.id] ||= {
id: n.id,
name: n.name,
wellBeing: [],
values: {},
},
acc[n.id].wellBeing.push(n['well-being']),
extractValues(acc[n.id], n, 'needs'),
extractValues(acc[n.id], n, 'provision'),
acc
), {}))
.map(n => ({
id: n.id,
name: n.name,
value: average(n.wellBeing),
values: Object.values(n.values).map(m => (
m.needs = average(m.needs),
m.provision = average(m.provision),
m
))
}));
const first = document.querySelector('#first');
const second = document.querySelector('#second');
const showOptions = {
1: [ '1', '11', '16' ],
2: [ '12', '14', '15' ],
};
first.addEventListener('change', function() {
const toShow = showOptions[this.value];
[...second].forEach(n => n.hidden = +n.value && toShow && !toShow.includes(n.value));
});
const nav = document.querySelector('.nav');
const itemSelector = '.nav-link';
const image = document.querySelector('.preview-img');
const category = document.querySelector('.preview-head');
function updatePreview(data) {
image.src = data.img;
category.textContent = data.category;
}
nav.querySelectorAll(itemSelector).forEach(function(n) {
n.addEventListener('mouseenter', this);
}, e => updatePreview(e.target.dataset));
nav.addEventListener('mouseover', e => {
const data = e.target.closest(itemSelector)?.dataset;
if (data) {
updatePreview(data);
}
});
function output(value) {
const digits = document.querySelectorAll('селектор span`ов');
const { length } = digits;
Array
.from(`${value}`.padStart(length, 0).slice(-length))
.forEach((n, i) => digits[i].innerText = n);
}
function output(value) {
document.querySelector('селектор родительского элемента span`ов').innerHTML = Array
.from(`${value}`, n => `<span>${n}</span>`)
.join('');
}
const [ first, ...rest ] = document.querySelectorAll('[type="checkbox"]');
const onChange = () => first.checked = rest.every(n => n.checked);
first.addEventListener('change', () => rest.forEach(n => n.checked = first.checked));
rest.forEach(n => n.addEventListener('change', onChange));