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

jQuery(function() {

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


and HTML code is

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

I added this but nothing is appear.


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:


| improve this answer | |
  • 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.