.spoiler_block div {
display: none;
}
$('.spoiler_title').click(function() {
$('.spoiler_block div').slideToggle(250);
});
function compoundMatch(words, target) {
const pairs = [];
for (let i = 1; i < target.length; i++) {
pairs.push([ target.slice(0, i), target.slice(i) ]);
}
for (const [ a, b ] of pairs) {
const ia = words.indexOf(a);
const ib = words.indexOf(b);
if (ia !== -1 && ib !== -1) {
return ia < ib ? [ a, b, [ ia, ib ] ] : [ b, a, [ ia, ib ] ];
}
}
return null;
}
function compoundMatch(words, target) {
const indices = {};
for (let i = 0; i < words.length; i++) {
const a = words[i];
if (!indices.hasOwnProperty(a)) {
indices[a] = i;
const b = target.replace(a, '');
if (indices.hasOwnProperty(b)) {
return [ b, a, a + b === target ? [ i, indices[b] ] : [ indices[b], i ] ];
}
}
}
return null;
}
function compoundMatch(words, target) {
const indices = {};
for (let i = 0; i < words.length; i++) {
indices[words[i]] = i;
}
for (const a in indices) {
for (const b in indices) {
if (a + b === target) {
return indices[a] < indices[b]
? [ a, b, [ indices[a], indices[b] ] ]
: [ b, a, [ indices[a], indices[b] ] ];
}
}
}
return null;
}
const values = {
'это может быть в первом столбце': 'а это надо будет подставить в третий',
'это тоже может оказаться в первом столбце': 'ну вы поняли, что здесь должно быть',
// ну и так далее
};
$('.table tr').each(function() {
const $td = $('td', this);
const key = $td.eq(0).text();
if (values.hasOwnProperty(key)) {
$td.eq(2).text(values[key]);
}
});
найти последний div
const last = document.querySelector('#container').lastElementChild;
остальные удалить
Array.prototype.reduceRight.call(
document.querySelector('#container').children,
(_, n) => n.nextElementSibling && n.remove()
);
const last = Array
.from(document.querySelector('#container').children)
.reduce((_, n, i, a) => i === a.length - 1 ? n : n.remove(), null);
const table = document.querySelector('table');
const className = 'red';
const indices = Array.from(table.querySelectorAll(`thead .${className}`), n => n.cellIndex);
table.querySelectorAll('tbody tr').forEach(n => {
indices.forEach(i => n.cells[i].classList.add(className));
});
for (const { cells } of table.querySelectorAll('tbody tr')) {
for (let i = 0, j = 0; i < cells.length; i++) {
j += cells[i].classList.toggle(className, i === indices[j]);
}
}
document.addEventListener('click', ({ target: t }) => {
if (t.classList.contains('box')) {
for (const n of document.querySelectorAll('.box')) {
n.style.background = n === t ? 'red' : 'black';
}
}
});
function getDatesGroupedByWeekday(year, month) {
const d = new Date(`${month} 1, ${year}`);
const iMonth = d.getMonth();
const result = {};
while (d.getMonth() === iMonth) {
const date = d.getDate();
const weekday = d.toLocaleString('en-US', { weekday: 'long' });
(result[weekday] = result[weekday] ?? []).push(date);
d.setDate(date + 1);
}
return result;
}
const block = document.querySelector('.block');
const parent = block.parentNode;
const childNodes = [...parent.childNodes];
const wrapper = document.createElement('div');
wrapper.classList.add('another__block');
wrapper.append(...childNodes.slice(childNodes.indexOf(block) + 1));
parent.append(wrapper);
fetch('https://jsonplaceholder.typicode.com/albums')
.then(r => r.json())
.then(r => {
document.body.insertAdjacentHTML('beforeend', `
<div class="wrapper">${r.map(n => `
<div class="item">
<div>UserId: ${n.userId}</div>
<div>Id: ${n.id}</div>
<div>Title: ${n.title}</div>
</div>`).join('')}
</div>
`);
});
.item {
border: 1px solid silver;
padding: 10px;
margin: 10px;
}
const fourValues = four.map(Object.values);
const result = three.map(n => {
const values = Object.values(n);
const intersections = fourValues.filter(m => values.every(v => m.includes(v)));
return `${values} - ${intersections.length
? `входит в / ${intersections.map(m => `${m}`).join(' / ')} /`
: 'нет вхождений'}`;
});
$('.bakeries-slider').each(function() {
$('.bakeries-slider__span', this).text(i => `${i + 1}.`);
});
for (const n of document.querySelectorAll('.bakeries-slider')) {
n.querySelectorAll('span').forEach((m, i) => m.innerText = ++i + '.');
}
[].forEach.call(document.getElementsByClassName('bakeries-slider'), n => {
const slides = n.getElementsByTagName('span');
for (let i = 0; i < slides.length; i++) {
slides[i].textContent = ''.concat(-~i, '.');
}
});
$('#m_prev').click
и $('#m_next').click
за пределы $('.norutyun img').click
. $('#sortable').sortable({
stop() {
const values = $('input[name="slider-id"]', this).get().map(n => n.value);
},
});