0

This question already has an answer here:

I am trying to get alert on click event of a tag, but it seems to be not working. Here is the code. I put this in header.php

<script>
jQuery(function() {

  jQuery('.neha').click(function () {
 var addressValue = $(this).attr("href");
        alert(addressValue );
  })

});
</script>

and HTML code is

<a class="neha" href="ID-1">neha</a>

I added this but nothing is appear.

marked as duplicate by fuxia Apr 9 '17 at 10:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

What do you mean nothing appears? You probably get redirected to other page (or 404 page). Try to prevent that, using function preventDefault, like this:

https://jsfiddle.net/dzonit/jck9cbnr/

  • Hey thanks.But the code is not working when I insert it into the wordpress header.php – nehaJ Apr 9 '17 at 17:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.