A
A
AndreyVolkov722021-07-15 19:16:51
JavaScript
AndreyVolkov72, 2021-07-15 19:16:51

Why does it find only the very first date attribute when there are more of them in the element?

There is an element in which there are two date attributes with the same name, but different values, when I search in JS using dataset, it finds only the first date attribute.
Why and how to fix it, or how to do it right from the start?
HTML

<div class="content-item" data-filters="Bluetooth" data-filters="google-assistant"></div>

JS
console.log(card.dataset.filters);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aidarDev, 2021-07-15
@AndreyVolkov72

try to make 1 data-filters, and enter all the necessary values ​​\u200b\u200bseparated by commas into it, then use js to transfer them to an array.

<div class="content-item" data-filters="Bluetooth,google-assistant"></div>

console.log(card.dataset.filters.split(','));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question