Can jQuery .load append instead of replace?
You can’t append content using the jQuery.load() method, but you can do what you want using jQuery.get(): $.get(‘/page/2/’, function(data){ $(data).find(“#articles .story”).appendTo(“#articles”); });
You can’t append content using the jQuery.load() method, but you can do what you want using jQuery.get(): $.get(‘/page/2/’, function(data){ $(data).find(“#articles .story”).appendTo(“#articles”); });
If you want any custom handling such as this, you simply can’t use the jQuery.load() function. You’ll have to upgrade to jQuery.ajax(), which I recommend anyway since you can do so much more with it, especially if you need any kind of error handling, it will be necessary. Use the beforeSend option for jQuery.ajax and … Read more
No need for ajax. You can create a new image element, set its source attribute and place it somewhere in the document once it has finished loading: var img = $(“<img />”).attr(‘src’, ‘http://somedomain.com/image.jpg’) .on(‘load’, function() { if (!this.complete || typeof this.naturalWidth == “undefined” || this.naturalWidth == 0) { alert(‘broken image!’); } else { $(“#something”).append(img); } … Read more
If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete, like this: $(“img”).one(“load”, function() { // do stuff }).each(function() { if(this.complete) { $(this).load(); // For jQuery < … Read more