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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…