Reputation: 1084
Is there a way in javascript to check if an element has a certain attribute value? Given this code:
<div class="wrapper">
<a href=#refresh-cart>view cart</a>
</div>
is there a way to be more specific rather than
document.addEventListener('click', e => {
if (e.target.hasAttribute('href')) {
//...
}
})
Upvotes: 1
Views: 555
Reputation: 943564
Get the value. Compare it to what you want.
if (e.target.getAttribute('href') === "foo")
Upvotes: 5