jQuery Live – Binding Future Elements

It is not the plugin. It is simply the live binding of events. I found this when I need to bind the click events of several buttons which are results from an AJAX search.

We can’t use bind on those buttons since they will appear only when there is a search result. Here is how we bind them.

$("input[id^='btn_']").live("click", function(e) {
    alert("your stuff here"); 
});

Simple isn’t it? I used the first 3 letters of the button’s ID as selector and used “^=” operator in jQuery to match elements starting on that string, since my buttons are in this format:

This entry was posted in JavaScript and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *