const makeTree = (root) => {
const tree = {};
const step = (root, branch) => {
root.querySelectorAll(':scope > [class^="block"]').forEach((element, index) => {
const className = [...element.classList.values()].find(
(className) => className.startsWith('block')
) ?? element.className;
const key = `${className}_${index + 1}`;
branch[key] = {};
const control = element.querySelector(':scope > input');
if (control) {
branch[key].value = control.value;
}
step(element, branch[key]);
});
};
step(root, tree);
return tree;
};
const tree = makeTree(document.body);
console.log(tree);
const makeTree = (root) => {
const tree = {};
const step = (root, branch) => {
root.querySelectorAll(':scope > [class^="block"]').forEach((element, index) => {
const className = [...element.classList.values()].find(
(className) => className.startsWith('block')
) ?? element.className;
const key = `${className}_${index + 1}`;
const controls = element.querySelectorAll(':scope > input');
branch[key] = {
values: [...controls].reduce((acc, control) => {
if (control.id) {
acc[control.id] = control.value;
}
return acc;
}, {})
};
step(element, branch[key]);
});
};
step(root, tree);
return tree;
};
const tree = makeTree(document.body);
console.log(tree);
const pages = Array.from({ length: Math.ceil(reposCount / elementsCount) }, (_, i) => i + 1);
const pages = new Array(Math.ceil(reposCount / elementsCount)).fill(null).map((_, i) => i + 1);
function* range(from, to) {
for (let i = from; i <= to; i++) {
yield i;
}
}
const pages = [...range(1, Math.ceil(reposCount / elementsCount))];
encodeURIComponent(
decodeURIComponent('test+%0D%0Atest.+%0D%0ADtestestestes%0D%0Atesgdsger%0D%0A')
.replace(/\+?\r\n/g, '+\r\n')
)
if (${data.title} != 'null')
такое вообще работать не будет.null
, то можно решить проблему так:moviesEl.textContent = data.title ?? 'Another title';
#
не нужно ставить в id
: href="#ID"
и id="ID"
, а Вы пишите href="#ID"
и id="#ID"
. cloneNode
не копирует события, о чём написано в документации.window.addEventListener('click', (event) => {
event.target.closest('.element__button')?.classList.toggle('element__button_active');
});
input
с типом checkbox
добавляете value
, причём у одинаковых значений value
должен совпадать. А дальше всё просто:$('input[type="checkbox"]').change(function (event) {
const checked = this.checked;
$(`input[type="checkbox"][value="${this.value}"]`).prop('checked', checked);
});