I am stuck on trying to write a function that would grab the class here in this element
<li class="list-group-item" data-id="1023649435">
And then add a class to it called modify-margin
I'm still relatively new at writing js, don't want to write it in jQuery and use just plain vanilla (or ES6).
I've made some progress with my function however I've got this problem where there is another list item that has the class:
which I don't want to affect that one, just the ones with list-group-item
The solution here would be if the element has dataset id
then grab only those, problem is I don't know how to grab datasets. Any help would be greatly appreciated.
Here's what I have so far and I know it's fairly basic. Thank you for the help in advance
init() {
const elems = document.querySelectorAll('.list-group-item');
console.log('elems', elems);
} }