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?

1 Answer 1

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")
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.