N
N
Norwood2020-04-25 14:37:28
JavaScript
Norwood, 2020-04-25 14:37:28

How to get the values ​​of all data attributes?

Can't get all values ​​from data-name. Only the first value works. Maybe someone will tell?

<div class="letters">
        <button class = "let" data-name='q'>q</button>
        <button class = "let" data-name='w'>w</button>
        <button class = "let" data-name='e'>e</button>
        <button class = "let" data-name='r'>r</button>
        <button class = "let" data-name='t'>t</button>
        <button class = "let" data-name='y'>y</button>
      </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-04-25
@Norwood

const values = [...document.querySelectorAll('[data-name]')].map(entry => entry.dataset.name);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question