$ ("body"). ready () works, but $ ("body"). load () not working?

Why? I have the same problem with image tag.

Call in progress

ready () callback. load () never starts.

Browser: Firefox3.6.8 on Mac

Edit:

I somehow feel like I am using load () incorrectly in jQuery. Documentation I mean: - http://api.jquery.com/load-event/

I do

$ ("body"). load (function () {// do something});

Is that not so? I see how the code works: $ ("# ID") load ("./newpage.html"). But are these 2 different APIs?

Edit 2

Another code to explain my whole problem here: -

var tagString = "<img id='"+imageId+"'></img>";
this.divElem.append(tagString);
var imgElems = $("#"+imageId);

var vowels = this;
imgElems.each(function (index) {
    $(this).attr('id',imgId).attr('src',imageUrl)
               .attr('width',1).attr('height',1);       
        $(this).load(function() { 
           // do something.
           // This Damned! function is never getting called!
        });

});

Work

 $().ready(function() {
    $().load(function() {
       /// something. this worked!
    });
 });

Does not work

    // without the ready() wrapper does not work
    $().load(function() {
       /// something. this worked!
    });

Why? I am happy that this works. But I do not understand why!

-Ajay

+3
3

, , :

$(window).load(function(){
  // do something
});

, body, , body. script ( script ), body , .

+8

, $("anything").ready() ... , . .load() , , , , , .

+3

.ready() .load() .

$("body").ready(onBodyLoaded);

https://api.jquery.com/ready/

onBodyLoaded, .

var url = some url
var data = {}
$("body").load( url , data, onComplete(responseText, textStatus, XMLHttpRequest) )

This tells the browser to request a URL, passing the data if POST, to the body, and then calling the onComplete function.

send https://api.jquery.com/load/

+1
source

Source: https://habr.com/ru/post/1782703/


All Articles