Why Can't I Get Jquery's Live() Or Load() To Work?
Why does only the third method work? $('#jqtest').live('load', function() {$(this).html('hi');}); //1 $('#jqtest').load(function() {$(this).html('hi');}); //2 $(window).load(fun
Solution 1:
You can't use the load()
function on arbitrary selectors; you can only use it on "any element associated with a URL: images, scripts, frames, iframes, and the window object" (docs). div
s don't have an associated URL, so neither of your first two techniques will bind a handler. window
does have a URL, so it will call the handler.
You might also also be interested in ready().
Solution 2:
If you're trying to add the HTML "hi" to the element "#jqtest" when the document or window has loaded you're almost there.
$(document).ready(function(){
$("#jqtest").html('hi');
});
This will change the value of "#jqtest" when the document has been loaded. You can also specify other events within the ready() function to only be executed once the page has fully loaded.
Post a Comment for "Why Can't I Get Jquery's Live() Or Load() To Work?"