1

I have a html code:

<a title="intro">INTRO?</a>

I need to link a jQuery click event on the tag. Using the solution given here I wrote the following javascript:

jQuery("a[title='intro']").click(alert("abc"));

However the page is alerting ("abc") on page load rather than on clicking the tag. Also to inform that the above code is NOT inside the load function jQuery(function() {... } and is a separate function.

Any solutions pls?

Community
  • 1
  • 1
user1517108
  • 2,395
  • 6
  • 32
  • 43

1 Answers1

3

You are invoking the alert function during the event registration and is passing the value returned by the alert as the click callback handler.

Instead you need to pass a function reference as the click callback and within the function you can add the alert call

jQuery("a[title='intro']").click(function(){
    alert("a")
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531