This might not be news to some, but if you are using older versions of jQuery, take note of a fairly significant change.

Ran across this today reading the jQuery API docs. The bind() and live() functions are deprecated as of v1.7, and have been removed as of v1.9. They are both being replaced with on().

http://api.jquery.com/on/

I tested changing to on() in some of my own projects, and found no difference in expected results when simply switching from bind() to on(). Just replace "bind" with "on" and you are good to go.

However, if you use live(), you will need to modify your code a little. The main reason I used live() was to have an event handler attached to an element now, or in the future if it's not currently part of the DOM. What you need to do now is attach the on() function to a containing element that will be present in the DOM from the beginning, and use a delegated event to catch the action of the element that will be in the DOM later. It's very straightforward.

Here's an example of that. I have a container DIV with an ID of "myContainer" that is always present in the HTML from the outset. Inside that DIV, HTML will be added later (like an AJAX request to populate it with some HTML based on a button click). Inside that new HTML will be a link that I want to trap and manage in some way. That link will have an id of "futureLink" for this example.

Before, you did this:

view plain print about
1$('#futureLink').live('click',function(e){
2    e.preventDefault();
3    alert("a link was clicked that wasn't here before");
4});

Here's what you do now:

view plain print about
1$('#myContainer').on('click','#futureLink',function(e){
2    e.preventDefault();
3    alert("a link was clicked that wasn't here before");
4});

So, a simple solution to future-proof your code as you upgrade versions of jQuery.