Reputation: 1584
I have an image in a div in one html doucment, whic is loaded by another document using this code:
$.get("injections.html", function(data) {
if ($('#header').length) {
$("#header").replaceWith(data.getElementById("header"))
}
});
It loads text just fine but when it loads images, they show up in the page inspection but not the page itself. Does anyone know why?
Upvotes: 0
Views: 63
Reputation: 111
The success callback function in jQuery's $.get and $.post (as well as $.ajax) will receive a string as parameter.
String.getElementById is undefined. Since you are already using jQuery, you may try the following:
$("#header").replaceWith($(data).find("#header"));
EDIT
The (first) parameter received by the callback is indeed a Javascript object (or what jQuery defines as 'PlainObject').
Upvotes: 2