jquery .live on load event

Posted by bandhunt on Stack Overflow See other posts from Stack Overflow or by bandhunt
Published on 2010-03-30T20:31:43Z Indexed on 2010/03/30 20:33 UTC
Read the original article Hit count: 959

Filed under:

I need a way to use the jquery .live() function to act on elements that are loaded via ajax.

For instance a div is loaded via ajax .load()

<div id="mydiv"></div>

Normally I do .live() with a click event, but I need to know how to tell the dom that this new div has loaded without any explicit actions/events from the user.

This code doesn't work, but I want to do something like this:

mydiv = $("#mydiv");

mydiv.live("mydiv.length > 0", function() {
       // do something
});

The "mydiv.length" being a substitue for the typical "click" or other event.

© Stack Overflow or respective owner

Related posts about jQuery