$('input').datepicker({
beforeShowDay: date => [ date.getDay() === 6 ],
});
$('input').datepicker({
onRenderCell: (date, cellType) => ({
disabled: cellType === 'day' && date.getDay() !== 6,
}),
});
$('select').change(function() {
console.log($(':selected', this).text());
});
это же мультиселект, и когда выбрано два элемента, то имена двух элементов и получаем, а мне нужно только тот который выбрали
$('select').on('click', 'option', function(e) {
const $target = $(e.target);
if ($target.is(':selected')) {
console.log($target.text());
}
});
let prevSelected = [];
$('select').on('change', function(e) {
const selected = $(':selected', this).get().map(n => n.innerText);
const newSelected = selected.find(n => !prevSelected.includes(n));
prevSelected = selected;
if (newSelected) {
console.log(newSelected);
}
});
const $popup = $('#popup_idea');
const $list = $('.list_idea');
$list.on('click', '.open_win_idea', function() {
$popup.data('del', $(this).closest('li').index()).fadeIn();
});
$('.close_win_butt_yes').click(function() {
$list.children().eq($popup.data('del')).remove();
$popup.fadeOut();
});
$('.close_win_butt_no, .close_win').click(function() {
$popup.fadeOut();
});
const str = $('.list li')
.get()
.map(n => $(n).text())
.join(' ');
const str = Array
.from(document.querySelectorAll('.list li'), n => n.innerText)
.join` `;
const str = Array.prototype.reduce.call(
document.querySelector('.list').children,
(acc, n, i) => acc + (i ? ' ' : '') + n.textContent,
''
);
$('.list_idea').on('click', '.open_win_idea', function() {
$(this)
.closest('li')
.find('p')
.attr('contenteditable', (i, val) => val !== 'true')
.focus();
});
$('li, div, p', '#wrapper').attr('custom-attr', i => `test${i + 1}`);
document
.querySelector('#wrapper')
.querySelectorAll('li, div, p')
.forEach((n, i) => n.setAttribute('custom-attr', 'test' + -~i));
success(response) {
$('#api-wb').html(JSON.parse(response).loads.map(n => `
<div class="item">
<div><b>${n.title}</b></div>
<div><a href="${n.comments_url}">comments (${n.comments_num})</a></div>
<div><img src="${n.files[0].small}"></div>
</div>
`).join(''));
}
const arr3 = arr1.map(n => (arr2.find(m => m.date === n) || { count: null }).count);
const obj = arr2.reduce((acc, n) => (acc[n.date] = n.count, acc), {});
const arr3 = arr1.map(n => obj[n] || null);
const arr3 = arr1.map(function(n) {
return this.get(n) || null;
}, new Map(arr2.map(n => [ n.date, n.count ])));
const statusArray = object.map(item => {
const opts = {
maxResults: 5,
key: users[2].token,
};
return new Promise((resolve, reject) => {
search(item.title, opts, (err, videos) => {
if (err) {
throw err;
}
item.youtubeId.new = videos[0].id;
item.videos = videos;
resolve(ArticleController.addArticle(item));
});
});
});
const parent = document.querySelector('ul');
const className = 'elem';
const count = 2;
for (let i = parent.children.length, j = count; i-- && j--;) {
parent.children[i].classList.remove(className);
}
// или
Array.prototype.forEach.call(parent.children, (n, i, a) => {
n.classList.toggle(className, i + count < a.length);
});
// или
parent.querySelectorAll(`.${className}:nth-last-child(-n + ${count})`).forEach(n => {
n.classList.value = n.classList.value.replace(RegExp(`(^| )${className}( |$)`), ' ').trim();
});
// или
for (
let i = 0, el = parent.lastElementChild;
i < count && el;
i++, el = el.previousElementSibling
) {
el.className = el.className.split(' ').filter(n => n !== className).join(' ');
}
$('.one .qwer').css('font-size', i => `${12 + i * 4}px`);
document.querySelectorAll('.one .qwer').forEach((n, i) => {
n.style.fontSize = (-~-~-~i << 2) + 'px';
});
const items = document.querySelectorAll('.one .qwer');
for (let i = 0, j = 12; i < items.length; i++, j += 4) {
items[i].style.setProperty('font-size', ''.concat(j, 'px'));
}
const getTableData = ({ rows: [ head, ...rows ] }) =>
rows.map(function({ cells: c }) {
return this.reduce((obj, key, i) => (
obj[key] = c[i].innerText,
obj
), {});
}, Array.from(head.cells, n => n.innerText));
const tableData = getTableData(document.querySelector('table'));
const selector = '.active';
.const $result = $(selector).nextAll().addBack();
// или
const result = document.querySelectorAll(`${selector}, ${selector} ~ *`);
// или
const result = [];
for (
let el = document.querySelector(selector);
el;
el = el.nextElementSibling
) {
result.push(el);
}
// или
const el = document.querySelector(selector);
const siblings = el ? [...el.parentNode.children] : [];
const result = siblings.slice(siblings.indexOf(el));
$('select').each(function() {
$(this).select2({
minimumResultsForSearch: Infinity,
dropdownParent: $(this).closest('.card-more'),
});
});