Assuming I have following mark up:
<div id="Movie" data-genre="horror">The Hills Have Eyes</div>
I know that I can access that element´s dataset attributes using:
document.getElementById("Movie").dataset.genre
or
document.getElementById("Movie").getAttribute("data-genre")
But is there a way to get all elements with the same genre without using any other feature? I am thinking about something like that:
document.getElementsByDataSetKey(key)
You could try querySelectorAll
document.querySelectorAll('[data-genre~="horror"]');
will give you all elements with data genre that contains horror.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With