Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

Refer to A-tag in javascript

$
0
0

I got a problem with reffering to my A-tag in javascript, this is my js-code:

'use strict';
document.addEventListener('DOMContentLoaded', init);

function init() {
  document.querySelector('.info .order').addEventListener('click', addToCart);
}

function addToCart(e) {
  e.preventDefault();
  alert("test");
}
<article data-id="2"><h3></h3><figure><img src="#"><figcaption></figcaption></figure><div class="info"><a class="order">Order</a></div></article>

If I click on the A-tag, the alert won't show up? BTW - The code works in snippit but it doesn't in PHPStorm.

Thanks in advance.


Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>