1

I have a link like

<a href="#" id="foo" class="bar_link">blah</a>

I have many of these and the id value is an integer corresponding to a record in a database.

I want to create a click handler to pass the id attribute value for a specific link into a function whenever that link is clicked.

Here is what I have tried, but I am not having success.

$(".bar_link").live('click', barDetailsInit($(this).attr('id')));

What do you think? Thx!

1

3 Answers 3

4

This will work

$('.bar_link').live('click', function() { 
    barDetailsInit(this.id);
});
Sign up to request clarification or add additional context in comments.

1 Comment

It sure does! Thanks so much!
2

Oops, you forgot to wrap the click event in an anomymous method.

$(".bar_link").live('click', function() { barDetailsInit($(this).attr('id')); });

Your version would pull this as whatever the scope that the line is running in (probably "window").

Comments

1

Try this instead:

$(".bar_link").live('click', function(event) {

    barDetailsInit($(this).attr('id')));

});

Basically you'll need to call your function from within the event callback, then at that point you have context and can call your function with the desired parameter.

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.