this.currentImg = Math.min(+this.currentImg + 1, this.maxImages - 1);
$('#results').on('change', 'tr', function(e) {
console.log(e, $(this).data('xxx'));
});
function displayLine(data) {
$('#results').append($(`
<tr>
<th scope="row">${importLines.length}</th>
<td><input class="checkbox" type="checkbox"></td>
<td>${data[0]}</td>
<td>${data[2]}</td>
<td>${data[11]}</td>
<td id="status-${data[0]}"><b><span style="color: orange">PENDING</span></b></td>
</tr>
`).data('xxx', data));
}
arr.propertyIsEnumerable(length) // => true
$(document).on('click', '.sandwitch', function () {
if ($(window).width() < 520) {
$(this).toggleClass('sandwitch--active');
$('.main-menu-list').slideToggle();
}
});
state = { field: newField, currentPlayer: newPlayer };
Object.assign(state, { ... })
. function foo(...args) {
console.log(args[N]);
}
function foo() {
console.log(arguments[N]);
}
function foo(...{ [N]: x }) {
console.log(x);
}
const cards = Array.from(
document.querySelectorAll('[data-component="card"]'),
n => new Card(n)
);
constructor(el) {
if (typeof el === 'string') {
return Array.from(document.querySelectorAll(el), n => new Card(n));
}
// дальше всё по-старому
const cards = new Card('[data-component="card"]');
Подозреваю, что виноват ".parents()"
.closest('.block')
или .parent().next('.slider-btns')
. <input type="text" value="0.00">
document.querySelector('input').addEventListener('keypress', function(e) {
e.preventDefault();
this.value = this.value.replace(/(0)(?!.*\1)/, e.key);
});
const index = arr.findIndex(n => n.id === id);
if (index !== -1) {
arr.splice(index, 1);
}
const newArr = arr.filter(n => n.id !== id);
for (let i = arr.length; i--;) {
if (arr[i].id === id) {
arr.splice(i, 1);
}
}
reduceRight
используется не совсем по назначения, как и оператор &&
):arr.reduceRight((_, n, i, a) => n.id === id && a.splice(i, 1), null);
let countDeleted = 0;
for (let i = 0; i < arr.length; i++) {
arr[i - countDeleted] = arr[i];
countDeleted += arr[i].id === id;
}
arr.length -= countDeleted;
arr.splice(0, arr.length, ...arr.filter(n => n.id !== id));
<input type="range" min="20" max="200" value="100">
<img src="...">
document.querySelector('input').addEventListener('input', function() {
document.querySelector('img').style.filter = `brightness(${this.value}%)`;
});
$('.box').each((i, n) => {
const $blocks = $('.section .block', n);
$('.imgs img', n).each((i, n) => $blocks.eq(i).append(n));
});
document.querySelectorAll('.box').forEach(n => {
const images = n.querySelectorAll('img');
n.querySelectorAll('.block').forEach((n, i) => n.append(images[i]));
});
return this.data();
const chunked = (data, chunkSize) =>
Array.prototype.reduce.call(
data,
(acc, n, i) => (
i = i / chunkSize | 0,
(acc[i] = acc[i] || []).push(n),
acc
),
[]
);
console.log(chunked([...Array(10).keys()], 3));
console.log(chunked('ABCDEFG', 2));
console.log(chunked(document.querySelectorAll('img'), 5));
for (let i = 0; i < answer.length - 1; i++)
for (let i = 0; i < words.length; i++)
p.style.color = colors[i]
.