$('ul').on('click', 'a', function() {
$(this).after($('.drop'));
// или
$('.drop').insertAfter(this);
});
document.querySelector('ul').addEventListener('click', e => {
if (e.target.tagName === 'A') {
e.target.after(document.querySelector('.drop'));
}
});
const dropEl = document.querySelector('.drop');
const onClick = e => e.target.insertAdjacentElement('afterend', dropEl);
document.querySelectorAll('ul a').forEach(n => n.addEventListener('click', onClick));
const $form = $('.order__form-contacts').on('change', '[name="legal-status"]', e => {
$form.find('.order__form-file')[e.target.value === '2' ? 'slideDown' : 'slideUp']();
});
arr1.forEach(function({ id }) {
if (this[id]) {
this[id].isAdded = true;
}
}, arr2.reduce((acc, n) => (acc[n.id] = n, acc), {}));
const newArr2 = arr2.map(function({ ...n }) {
if (this.has(n.id)) {
n.isAdded = true;
}
return n;
}, new Set(arr1.map(n => n.id)));
const text = 'определённый текст';
const link = document.querySelector(`a[href*="${text}"]`);
if (link) {
link.click();
}
.click()
на [0].click()
или .get(0).click()
. const $filters = $('.filter').change(function() {
const filters = $filters
.get()
.filter(n => n.value)
.map(n => [ n.dataset.name, n.value ]);
$('.product')
.hide()
.filter((_, el) => filters.every(n => el.dataset[n[0]] === n[1]))
.show();
});
.modal-wrapper .open {
должно быть .modal-wrapper.open {
. blur
, а не focus
toUpperCase
не у строки, а у массива - забыто [0]
input.addEventListener('blur', function() {
if (this.value) {
this.value = this.value.split(/\s+/).map(n => n[0].toUpperCase() + n.slice(1)).join(' ');
}
});
const getPrimitiveProps = (obj) =>
Object.entries(obj).reduce((acc, [ k, v ]) => ({
...acc,
...(v instanceof Object ? getPrimitiveProps(v) : { [k]: v }),
}), {});
const getPrimitiveProps = (obj) =>
Object.assign({}, ...Object.entries(obj).map(([ k, v ]) =>
v instanceof Object ? getPrimitiveProps(v) : { [k]: v }
));
$(document).click(function(e) {
if (!$panel.has(e.target).length && $panel.hasClass('visible')) {
hidePanel();
}
});
const ip = str.split(':', 1)[0];
const ip = str.slice(0, str.indexOf(':'));
const ip = str.match(/[\d.]+/).pop();
const ip = str.replace(/:.+$/, '');
const [ ip ] = /.+(?=:)/.exec(str);
const plainToNested = (source, target = {}) =>
Object.entries(source).reduce((acc, [ path, val ]) => {
const keys = path.split('.');
const key = keys.pop();
keys.reduce((p, c) => p[c] = p[c] || {}, acc)[key] = val;
return acc;
}, target);
const buttonSelector = '.one-click-button';
const dataAttr = 'id';
const input = document.querySelector('#one_b_id');
const getId = el => el.dataset[dataAttr];
// или
const getId = el => el.getAttribute(`data-${dataAttr}`);
// или
const getId = el => el.attributes['data-' + dataAttr].value;
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
input.value = getId(button);
}
});
document.querySelectorAll(buttonSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => input.value = getId(e.currentTarget));
Как я могу проверить на наличие в начале строки undefined и удалить её?
str.replace(/^undefined/, '')
.