My Technology Reference

jQuery click event handler doesn’t work – use live :)

Posted in Microsoft .Net, Web by DK on February 22, 2011

If you are trying to use jQuery .click() event handling on dynamically added elements/controls, you might notice something that looks like click event never getting fired. This happens because click handler gets set on current set of elements only. For dynamic elements you have to use something that handles future elements as well.

When I saw it first time, I thought I found a bug in either jQuery or browser or both. Anyways, this particular case is not a bug.

Answer is using .live().

Example:

$("#ID").live("click", function() {
// Handler code
});

Advertisement
Tagged with: ,

2 Responses

Subscribe to comments with RSS.

  1. Erwin Martling said, on March 1, 2011 at 12:00 am

    I simply want to tell you that I am newbie to weblog and actually savored this website. Almost certainly I’m going to bookmark your site . You amazingly have really good articles. Bless you for sharing with us your website.

  2. international business directory said, on March 20, 2011 at 12:42 am

    Specialized niche web directories are still important as ever before .


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.