что делаю не так?
active на кнопке? Его у элемента с классом d-n переключать надо - вместо той ерунды с изменением стилей напрямую. Кстати, а кому вы пытаетесь назначить style.display = 'table-cell'? Если идти от кнопки parent-parent-next (вместо того, чтобы несколько раз дёргать parentNode, следует использовать метод closest) - это будет (не будет, погуглите, в чём разница между nextSibling и nextElementSibling) строка, а не ячейка - так что перенесите-ка класс d-n на один уровень выше. Зачем создавать каждой кнопке индивидуальный обработчик? Достаточно одного на всех, создавайте его вне цикла. Наконец, у classList.toggle есть второй параметр, не надо им пренебрегать.document.querySelectorAll('.panel').forEach(n => n.addEventListener('click', onClick));
function onClick() {
const panel = this.closest('tr').nextElementSibling;
const isActive = !panel.classList.contains('active');
panel.classList.toggle('active', isActive);
this.classList.toggle('changing-icon', isActive);
}
мне нужен не сам ответ
function findOutlier(integers) {
const [ p0, p1, p2 ] = integers.slice(0, 3).map(n => n & 1);
return p0 === p1
? integers.find(n => (n & 1) !== p0)
: integers[+(p0 === p2)];
}const findOutlier = arr => arr
.reduce((acc, n) => (acc[n & 1].push(n), acc), [ [], [] ])
.find(n => n.length === 1)
.pop();const findOutlier = arr => arr
.sort((a, b) => (a & 1) - (b & 1))
.at(-((arr[0] & 1) === (arr[1] & 1)));
useEffect(() => { document.querySelector('.App').classList.toggle(theme) }, [theme])
useEffect(() => {
const el = document.querySelector('.App');
el.classList.add(theme);
return () => el.classList.remove(theme);
}, [ theme ]);
useEffect(() => {
const newArray = initialState.filter(n => checked.every(m => n[m]));
setData(newArray.length ? newArray : initialState);
}, [ checked ]);
function getFilterByCount(arr, filterFn, key = n => n) {
const getKey = key instanceof Function ? key : n => n[key];
const count = arr.reduce((acc, n) => {
const k = getKey(n);
return acc.set(k, -~acc.get(k));
}, new Map);
return n => !!filterFn(count.get(getKey(n)));
}const filterByCount = (...args) =>
args[0].filter(getFilterByCount(...args));
const newArr = filterByCount(arr, count => count > 1, 'props1');function deleteByCount(arr, filterFn, key) {
const f = getFilterByCount(arr, filterFn, key);
arr.length -= arr.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + f(n)
), 0);
}
deleteByCount(arr, count => count < 2, n => n.props1);
<button @click="onClick">click me</button>
<apexchart
ref="chart"
...methods: {
onClick() {
this.$refs.chart.zoomX(...);
},
...
isFlipped[index] = !isFlipped[index] setIsFlipped(isFlipped)
setIsFlipped(isFlipped.map((n, i) => i === index ? !n : n));
for(var i = 0; i < tabss.children.length;i++); { tabss.children[i].classList.add('active') }
i имеет значение tabss.children.length, элемента с таким индексом в tabss.children нет, ну и... ошибку вы видели.
.spoiler__button path {
transition: fill .7s ease-in-out;
+ fill: #ECECEC;
}
const createTreeFromNestedSets = arr => [...arr]
.sort((a, b) => a.left - b.left)
.reduce((acc, n) => {
while (acc.at(-1).at(-1).right < n.left) {
acc.pop();
}
if (acc.at(-1).at(-1).right > n.left) {
acc.push(acc.at(-1).at(-1).children);
}
acc.at(-1).push({ ...n, children: [] });
return acc;
}, [ [ { left: -Infinity, right: Infinity, children: [] } ] ])
[0][0].children;const createTreeHTML = (arr, nodeTemplate) =>
Array.isArray(arr) && arr.length
? `<ul>${arr.map(n => `
<li>
${nodeTemplate(n)}
${createTreeHTML(n.children, nodeTemplate)}
</li>`).join('')}
</ul>`
: '';containerElement.insertAdjacentHTML('beforeend', createTreeHTML(
createTreeFromNestedSets(data),
item => `<input data-id="${item.id}" type="checkbox">${item.name}`
));
function getDates(startStr, endStr) {
const startDate = new Date(startStr.split('.').reverse().join('-'));
const endDate = new Date(endStr.split('.').reverse().join('-'));
const dates = [];
for (; startDate <= endDate; startDate.setDate(startDate.getDate() + 1)) {
dates.push(startDate.toLocaleDateString('ru-RU', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}));
}
return dates;
}
Все делал как в инструкции
var chart = document.querySelector('.chart').then(function(response) { chart.updateSeries([{ name: 'Sales', data: response.data }]) })
.then(response => {
this.series = [
{
name: 'Sales',
data: response.data,
},
];
});
const Property = ({ data, onDelete }) => (
<div>
#{data.id}
<button onClick={onDelete}>Del</button>
</div>
);
const ConstructorPage = () => {
const [ properties, setProperties ] = useState([]);
const delProperty = property => setProperties(properties.filter(n => n !== property));
const addProperty = () => setProperties([
...properties,
{
id: 1 + Math.max(0, ...properties.map(n => n.id)),
},
]);
return (
<>
<button onClick={addProperty}>Add</button>
{properties.map(n => (
<Property
key={n.id}
data={n}
onDelete={() => delProperty(n)}
/>
))}
</>
);
};
const inputs = [...document.getElementsByClassName('inputs')];
function onInput() {
if (this.value.length === this.maxLength) {
inputs[-~inputs.indexOf(this)]?.focus();
}
if (inputs.every(n => n.value.length === n.maxLength)) {
console.log('ВСЕ ЗАПОЛНЕНЫ');
}
}
for (const n of inputs) {
n.addEventListener('input', onInput);
}const inputs = document.querySelectorAll('.inputs');
inputs.forEach(function(n) {
n.addEventListener('input', this);
}, function({ target: t }) {
const isFilled = t.value.length === t.maxLength;
if (isFilled) {
t.nextElementSibling?.focus();
}
if (this[isFilled ? 'add' : 'delete'](t).size === inputs.length) {
console.log('ВСЕ ЗАПОЛНЕНЫ');
}
}.bind(new Set));
data: () => ({
employees: [
{ ..., actions: [ 'delete', 'ещё что-то', 'и ещё' ] },
...
],
...props: {
columns: Array,
data: Array,
},<table>
<thead>
<tr>
<th v-for="(col, colIndex) in columns" :key="col.key">{{ col.label }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, rowIndex) in data" :key="row.id">
<td
v-for="col in columns"
:key="col.key"
:data-label="col.label"
>
<slot
:name="`column.${col.key}`"
:col-data="col"
:col-index="colIndex"
:row-data="row"
:row-index="rowIndex"
>
{{ row[col.key] }}
</slot>
</td>
</tr>
</tbody>
</table><v-table :columns="titles" :data="employees">
<template #column.actions="{ rowData, rowIndex }">
<div>
<button
v-for="action in rowData.actions"
v-text="action"
@click="onActionClick(action, rowData, rowIndex)"
></button>
</div>
</template>
</v-table>methods: {
onActionClick(action, row, index) {
switch (action) {
case 'delete':
this.employees.splice(index, 1);
return;
case 'ещё что-то':
this.сделатьЧтоТоЕщё(row);
return;
}
},
...
const blockSelector = '.block';
const buttonSelector = `${blockSelector} .block__close`;document.addEventListener('click', e => {
e.target.closest(buttonSelector)?.closest(blockSelector).remove();
});document.querySelectorAll(buttonSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => e.currentTarget.closest(blockSelector).replaceWith());
setState({ ...state, show: !state.show });.
не затрагивая строчку sort
users.sort((a,b) => a- b);valueOf() {
return this.age;
},toString на[Symbol.toPrimitive](hint) {
return hint === 'number'
? this.age
: `${this.name} is ${this.age} y.o.`;
},