$('.wrap').on('input', function(e) {
const valid = $(this).find('.valid').get().map(el => {
if (el === e.target) {
$(el).toggleClass('empty', !el.value);
}
return el.value;
}).every(Boolean);
$('.btn')
.toggleClass('btn--isvalid', valid)
.toggleClass('btn--novalid', !valid);
});
$('.form-group').trigger('input')
. const classes = [
{ maxLen: 15, name: 'length-15' },
{ maxLen: 30, name: 'length-30' },
{ maxLen: 45, name: 'length-45' },
];
document.querySelectorAll('.container').forEach(n => {
const len = n.textContent.length;
const cls = classes.find(m => m.maxLen >= len);
if (cls) {
n.classList.add(cls.name);
}
});
arr.sort((a, b) => (a.finishedDate || a.createdDate) - (b.finishedDate || b.createdDate));
document.querySelector('input').addEventListener('input', e => {
const
val = e.target.value,
reg = RegExp(val, 'gi'),
keys = [ 'firstName', 'lastName' ];
document.querySelector('.autocomplete-suggestions__list').innerHTML = val && people
.map(n => keys.map(k => n[k]).join(' '))
.filter(n => (reg.lastIndex = 0, reg.test(n)))
.map(n => `<div>${n.replace(reg, '<strong>$&</strong>')}</div>`)
.join('');
});
.html($(this).find('img'))
.html($(this).find('img').clone())
.items-left
, а проверяете количество .items-right
. Думали, что класс сам собой заменится? Нет, так не будет. const getImg = url => fetch(url)
.then(r => r.blob())
.then(blob => new Promise(resolve => {
const reader = new FileReader();
reader.addEventListener('loadend', () => resolve({ image: reader.result }));
reader.readAsDataURL(blob);
}));
document.querySelector('button').addEventListener('click', async () => {
const arrImg = await Promise.all(arr.map(n => getImg(`./images/${n}`)));
console.log(arrImg);
});
const $items = $('.card');
const openedClass = 'card--opened';
const closedClass = 'card--closed';
const delay = 500;
const flip = $item => $item.removeClass(closedClass).addClass(openedClass);
$items.each((i, n) => setTimeout(flip, (i + 1) * delay, $(n)));
(function next(i) {
if (i < $items.length) {
setTimeout(() => {
flip($items.eq(i));
next(-~i);
}, delay);
}
})(0);
let i = 0;
const intervalID = setInterval(() => {
flip($items.eq(i));
if (++i >= $items.length) {
clearInterval(intervalID);
}
}, delay);
const obj = array.reduce((acc, n, i) => (
acc[`filter${i + 1}`] = { ...baseFilter, prop: n },
acc
), {});
const obj = {};
for (const [ i, n ] of array.entries()) {
(obj['filter' + (-~i)] = Object.assign({}, baseFilter)).prop = n;
}
const obj = {};
for (let i = 0; i < array.length;) {
const subobj = { prop: array[i] };
for (const k in baseFilter) {
subobj[k] = baseFilter[k];
}
obj['filter'.concat(++i)] = subobj;
}
const [ arr1, arr2 ] = arr.list
.map(n => [ n, +n.pos.dv.slice(1) ])
.sort((a, b) => a[1] - b[1])
.reduce((acc, n) => (acc[+(n[1] >= 38)].push(n[0]), acc), [ [], [] ])
.map(n => ({ list: n }));
.red {
background: red;
}
$('.table').on('change', function(e) {
const $tr = $(e.target).closest('tr');
const ajaxdata = $tr.find('.ajaxdata').val();
const subcat = $tr.find('.subcat').val();
$tr.toggleClass('red', ajaxdata === 'none' && subcat === 'none');
}).find('tr').change();
// или
const table = document.querySelector('table');
table.addEventListener('change', e => {
const tr = e.target.closest('tr');
const ajaxdata = tr.querySelector('.ajaxdata').value;
const subcat = tr.querySelector('.subcat').value;
tr.classList.toggle('red', ajaxdata === 'none' && subcat === 'none');
})
table.querySelectorAll('tr').forEach(n => {
n.dispatchEvent(new Event('change', { bubbles: true }));
});
const mustStay = arr => arr.every(n => n.value !== '-');
const newArr = arr.filter(mustStay);
arr.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), null);
// или
arr.splice(0, arr.length, ...arr.filter(mustStay));
// или
let numDeleted = 0;
for (const [ i, n ] of arr.entries()) {
arr[i - numDeleted] = n;
numDeleted += !mustStay(n);
}
arr.length -= numDeleted;
const length = Math.max(...arr.map(n => n.length));
for (const n of arr) {
const id = 1 + Math.max(0, ...n.map(m => m.id));
n.push(...Array.from(
{ length: length - n.length },
(_, i) => ({ id: id + i, value: '_' })
));
}
const newArr = arr.map(n => Array.from({ length }, (_, i) => ({
id: i + 1,
value: i < n.length ? n[i].value : '-',
})));