Goal: get the data-element from the button that is been clicked.
My current code:
Array.from(document.getElementsByClassName('my_buttons_class')).forEach((button) => {
button.addEventListener('click', (e)=>{
e.preventDefault();
/*
Here i want to get the 'data-element' from the clicked button
something like
e.target.attr('data-element');
*/
})
});
The button element is something like this:
<button class="my_buttons_class" data-element="some json">My button text</button>
Current problem: the listener works fine, but the e.target is just the HTML text of that element, so i can't use .attr() on it
Also already tried e.target['data-element'] but it return undefined