this внутри обработчика клика? Не тем, что вам кажется. Замените $(this).attr("href") на $(event.target).attr("href") или стрелочную функцию на обычную.
msg.razd массив значений:const arr = Object.values(msg.razd);.const categories = arr.flatMap(n => n.category);
// или
const categories = [].concat.apply([], arr.map(n => n.category));
// или
const categories = arr.reduce((acc, n) => (acc.push(...n.category), acc), []);const result = categories.filter(n => expect.includes(n._id));
// или
const result = categories.filter(function(n) {
return this.has(n._id);
}, new Set(expect));
// или
const categoriesObj = Object.fromEntries(categories.map(n => [ n._id, n ]));
const result = expect.reduce((acc, n) => ((n = categoriesObj[n]) && acc.push(n), acc), []);
setTimeout((current) => pika[current].classList.toggle('active'), 100, current)
const $test = $('.test').on('click', '.testText', function() {
$test.append($(this).clone());
});$('.testText').click(function() {
$('.test').append($(this).clone(true));
});
data-country почему-то на русском - какого чёрта? Надо, чтобы были такими же, как и id у элементов .tabcontent.const tabLinks = document.querySelectorAll('.tablinks');
const tabContent = document.querySelectorAll('.tabcontent');
tabLinks.forEach(n => n.addEventListener('click', openTab));
function openTab({ currentTarget: t }) {
const { country } = t.dataset;
tabLinks.forEach(n => n.classList.toggle('active', n === t));
tabContent.forEach(n => n.classList.toggle('active', n.id === country));
// или, к чёрту data-атрибуты и id, можно индексами воспользоваться;
// конечно, в этом случае необходимо, чтобы .tablinks и соответствующие им
// .tabcontent были расположены в одинаковом порядке
const index = Array.prototype.indexOf.call(tabLinks, t);
tabLinks.forEach(n => n.classList.toggle('active', n === t));
tabContent.forEach((n, i) => n.classList.toggle('active', i === index));
}
const info = new google.maps.InfoWindow();marker.addListener('click', function() {
info.setContent('сюда засовываете свою информацию');
info.open(map, marker);
});
$('p i').text((i, text) => i % 3 ? text : 'hello, world!!');document.querySelectorAll('p i').forEach((n, i) => {
n.textContent = i % 3 ? n.textContent : 'fuck the world';
});p общий родитель, то можно и не смотреть на индекс, сразу нужные элементы получить:for (const n of document.querySelectorAll('p:nth-of-type(3n + 1) i')) {
n.innerText = 'fuck everything';
}
if (inputs[el].value == "") el++; if (inputs[el].value.match(/[А-я]/)) {
moment.locale('ru');
document.querySelector('#load').addEventListener('click', function load() {
fetch('https://api.github.com/users/fristyr/repos')
.then(r => r.json())
.then(data => {
const formatIn = 'YYYY-MM-DDTHH:mm:ss';
const formatOut = 'DD MMMM YYYY';
document.querySelector('.repo-wrapp').insertAdjacentHTML('afterbegin', data.map(item => `
<article class="repo">
<a href="${item.html_url}" class="repo__name">${item.name}</a>
<br>
<span class="repo__technology">${item.language}</span>
<span class="repo__update">${moment(item.updated_at, formatIn).format(formatOut)}</span>
</article>`
).join(' '));
});
});
<div id="slider"></div>
<div id="value"></div>const min = 100;
const max = 500;
$('#slider').slider({
min,
max,
value: min + Math.random() * (max - min) | 0,
range: 'min',
animate: 'fast',
slide: (e, ui) => $('#value').html(max - ui.value + min),
});
const options = [
[ 'hello, world!!', 'fuck the world', 'fuck everything' ],
500,
(elem => item => elem.textContent = item)
(document.querySelector('.slide-words')),
];function interval(arr, delay, callback) {
let i = -1;
return arr.length
? setInterval(() => callback(arr[i = -~i % arr.length]), delay)
: null;
}
const intervalId = interval(...options);
// надо остановить, делаем так: clearInterval(intervalId);function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function next(i) {
timeoutId = setTimeout(() => {
callback(arr[i]);
next((i + 1) % arr.length);
}, delay);
})(0);
return () => clearTimeout(timeoutId);
}
const stop = interval.apply(null, options);
// надо остановить, делаем так: stop();
parseInt('') будет NaN.0 вместо мусорных результатов парсинга, замените parseInt($(this).val()) на parseInt($(this).val()) || 0.
<span>hello, world!!... fuck the world... fuck everything</span>body {
margin: 0;
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
span {
color: red;
font-size: 24px;
font-family: monospace;
}
.xxx {
display: inline-block;
min-width: 10px;
transition: all 0.2s;
transform: scale(1);
}
.hidden {
opacity: 0;
transform: scale(30);
}function show(el) {
el.innerHTML = Array
.from(el.innerText, n => `<span class="xxx hidden">${n}</span>`)
.join('');
el.querySelectorAll('span').forEach((n, i) => {
setTimeout(() => n.classList.remove('hidden'), 100 * i);
});
}
show(document.querySelector('span'));
const getText = el => el.textContent;
// или
const getText = el => el.innerText;
// или
const getText = el => el.innerHTML;
// или
const getText = el => el.lastChild.nodeValue;
// или
const getText = el => el.childNodes[0].data;const getValue = text => text.match(/"(.*?)"/)[1];
// или
const getValue = text => text.split('"').slice(-2).shift();
// или
const getValue = text => text.replace(/^.*?"|"[^"]*$/g, '');
//
const getValue = text => `${/(?<=")[^"]+/.exec(text)}`;
// или
const getValue = text =>
JSON.parse(text.slice(-~text.indexOf('['), text.indexOf(']')));document.querySelectorAll('li button').forEach(function(n) {
n.addEventListener('click', this);
}, e => console.log(getValue(getText(e.target))));
// или
document.querySelector('ul').addEventListener('click', ({ target: t }) => {
if (t.tagName === 'BUTTON') {
console.log(getValue(getText(t)));
}
});