+
вам в помощь, добавляйте сколько надо.// исправляем ваш код
$('.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.classList.contains('style-count-plus') ? +1 :
t.classList.contains('style-count-minus') ? -1 :
0;
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.appendChild(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,
);
$.fn.customSelect = function() {
return this.each(function() {
const $this = $(this).hide();
const $wrapper = $this.wrap('<div class="select_wrapper"></div>').parent();
$wrapper.append(`
<span>${$this.find(':selected').text()}</span>
<ul class="select_inner">${$this.children().get().map(n => `
<li data-value="${n.value}">${n.innerText}</li>`).join('')}
</ul>
`);
$wrapper.on('click', 'li', function() {
$wrapper.children('span').text(this.innerText);
$this.val(this.dataset.value).trigger('change');
});
$wrapper.on('click', function() {
$('ul', this).slideToggle('fast');
});
});
};
$('#materialColor, #kantcolor').customSelect().change(function() {
console.log(`#${this.id}: "${this.value}"`);
});
$('.datepicker-input').datepicker({
minDate: 0,
onClose(dateText, inst) {
$(this).parent().next('.date').text([
inst.selectedDay,
inst.selectedMonth + 1,
inst.selectedYear
].join('-'));
}
});
$('.date').click(function() {
$(this).prev('div').find('.datepicker-input').focus();
});
const ancestor = 'селектор элементов, которые надо получить';
const descendant = 'селектор вложенных элементов';
Array.prototype.filter.call(
document.querySelectorAll(ancestor),
n => n.querySelector(descendant)
)
Array.from(
document.querySelectorAll(`${ancestor} ${descendant}`),
n => n.closest(ancestor)
)
[...document.querySelectorAll(descendant)].reduce(
(acc, n) => ((n = n.closest(ancestor)) && acc.push(n), acc),
[]
)
document.querySelectorAll(`${ancestor}:has(${descendant})`)
[
{ del: 'region_id', search: 'regionName' },
{ del: 'district_id', search: 'districtName' },
{ del: 'area_id', search: 'areaName' },
{ del: 'city_id', search: 'cityName' },
{ del: 'place_id', search: 'cityName' },
{ del: 'name', search: 'streetName' },
].forEach(n => {
if (this.tableParam[n.del]) {
delete this.tableParam[n.del];
this.searchForm.get(n.search).patchValue(null);
}
});