$(this).prev(value).html(this.value);
$(this).prev(value).find('.range-slider__value').html(this.value);
$('select').select2({
minimumResultsForSearch: Infinity,
dropdownParent: $('.card-more'),
});
const $li = $('ul li').show().slice(8).hide();
$('#loadMore').on('click', function(e) {
e.preventDefault();
$li.fadeToggle();
});
get-age
- это не data-атрибут. Меняйте на data-age
.age_3_6
будет .age_3_6
, вместо age_7_10
будет .age_7_10
и т.д., ну а у элемента "все" будет data-age="*"
.const itemSelector = '.ped_holder .ped';
const buttonSelector = '.ages a';
const activeButtonClass = 'active';
const selectorAttr = 'age';
const $buttons = $(buttonSelector).click(function() {
const selector = $buttons
.removeClass(activeButtonClass)
.filter(this)
.addClass(activeButtonClass)
.data(selectorAttr);
$(itemSelector).hide().filter(selector).show();
});
// или, к чёрту jquery
const buttons = document.querySelectorAll(buttonSelector);
const items = document.querySelectorAll(itemSelector);
buttons.forEach(n => n.addEventListener('click', onClick));
function onClick({ target: t }) {
const selector = t.dataset[selectorAttr];
buttons.forEach(n => n.classList.toggle(activeButtonClass, n === t));
items.forEach(n => n.style.display = n.matches(selector) ? '' : 'none');
}
arr.sort((a, b) => {
a = a.split('.', 2);
b = b.split('.', 2);
return (a[1] - b[1]) || (a[0] - b[0]);
});
const sortedArr = arr
.map(n => n.split('.'))
.sort((a, b) => (a[1] - b[1]) || (a[0] - b[0]))
.map(n => n.join('.'));
+
вам в помощь, добавляйте сколько надо.// исправляем ваш код
$('.add-attr').on('click', function() {
const index = $('.radios').length + 1;
const $lastRow = $(this).closest('.container').find('.item').last();
const $newRow = $lastRow.clone(true).insertAfter($lastRow);
$newRow.find('input[type="radio"]').prop('name', 'name-' + index);
});
// или переписываем его без использования jquery
document.querySelector('.container').addEventListener('click', e => {
if (e.target.classList.contains('add-attr')) {
const row = e.currentTarget.firstElementChild.cloneNode(true);
const name = `name-${e.currentTarget.children.length + 1}`;
e.currentTarget.appendChild(row);
row.querySelectorAll('[type="radio"]').forEach(n => n.name = name);
}
});
const $row = $('.b-items').clone();
let ID = +$row.find('select').last().attr('id').split('-').pop();
function selectize($el) {
$el.selectize({
allowEmptyOption: true,
create: true,
});
}
selectize($('select'));
$('.btn-clone').on('click', function() {
selectize($row
.clone()
.insertBefore(this)
.find('select')
.attr('id', () => `select-${++ID}`)
);
});
$('.intro')
.filter((i, n) => $(n).text().toLowerCase().includes(t))
.css('background-color', 'silver');
for (const n of document.getElementsByClassName('intro')) {
if (n.textContent.toLowerCase().indexOf(t) !== -1) {
n.style.backgroundColor = 'silver';
}
}
.highlight {
background-color: silver;
}
document.querySelectorAll('.intro').forEach(function(n) {
n.classList.toggle('highlight', ~n.innerText.search(this));
}, RegExp(t, 'i'));
function setOnClick(selector, change) {
function onClick({ target: t }) {
const el = t.closest('.style-item_count').querySelector('.style-count-number');
el.innerText = el.innerText.replace(/\d+/, m => Math.max(0, +m + change));
}
document.querySelectorAll(selector).forEach(n => n.addEventListener('click', onClick));
}
setOnClick('.style-count-plus', 1);
setOnClick('.style-count-minus', -1);
// или
function setOnClick(selector, change) {
$(selector).on('click', e => {
$(e.target)
.closest('.style-item_count')
.find('.style-count-number')
.text((i, text) => `${Math.max(0, parseInt(text) + change)} шт`);
});
}
document.addEventListener('click', ({ target: t }) => {
const change = +t.matches('.style-count-plus') || -t.matches('.style-count-minus');
if (change) {
const el = t.closest('.style-item_count').querySelector('.style-count-number');
el.innerText = `${Math.max(0, parseInt(el.innerText) + change)} шт`;
}
});
// или
$(document).on('click', '.style-count-plus, .style-count-minus', e => {
const $target = $(e.target);
const change = $target.hasClass('style-count-plus') ? 1 : -1;
$target
.closest('.style-item_count')
.find('.style-count-number')
.text((i, text) => text.replace(/\d+/, m => Math.max(0, +m + change)));
});
<div class="style-item_count">
<div class="style-count-minus" data-change="-1">-</div>
<div class="style-count-number"><span>1</span> шт</div>
<div class="style-count-plus" data-change="+1">+</div>
</div>
document.addEventListener('click', ({ target: t }) => {
const change = +t.dataset.change;
if (change) {
const el = t.closest('.style-item_count').querySelector('.style-count-number span');
el.textContent = Math.max(0, +el.textContent + change);
}
});
// или
$(document).on('click', '[data-change]', function() {
$(this)
.closest('.style-item_count')
.find('.style-count-number span')
.text((i, text) => Math.max(0, +text + +this.dataset.change));
});
const banners = [...document.querySelectorAll('.banner')];
for (let i = banners.length; --i > 0;) {
const j = Math.random() * (i + 1) | 0;
[ banners[i], banners[j] ] = [ banners[j], banners[i] ];
}
document.querySelectorAll('.products--container').forEach((n, i) => n.append(banners[i]));
arr.map(n => Object
.entries(n)
.reduce((acc, [ k, v ]) => (
acc[k] = v
.flatMap(Object.entries)
.map(([ k, v ]) => ({ [k]: v })),
acc
), {})
)
const isLinks = Array
.from(ul.querySelectorAll(':scope > li'))
.every(n => n.childNodes.length === 1 && n.childNodes[0] instanceof HTMLAnchorElement);
const isLinks = Array.prototype.every.call(
ul.children,
({ childNodes: [ a, b ] }) => a.tagName === 'A' && !b,
);