Reputation: 12421
I am taking a dom element in a variable and then erasing it. When I append that variable to the dom at some other place it does not appear in all versions of IE. Whereas it works fine in chrome and FF
Fiddle - http://jsfiddle.net/NdtNP/
HTML:
<div id="d1" style="color:red">sdjkfk
<a href="google.com">Click here</a>
sjlfkj df
</div>
<div id="d2"></div>
JS:
$(function(){
var a = $("#d1").children("a");
$("#d1").html("");
$("#d2").append(a);
});
How can I avoid this?
Upvotes: 2
Views: 47
Reputation: 869
Why not try to append before deleting by switching up your script like this
$(function(){
var a = $("#d1").children("a");
$("#d2").append(a);
$("#d1").html("");
});
Upvotes: 1
Reputation: 57095
Use .detach()
$(function () {
var a = $("#d1").children("a").detach();
$("#d1").html("");
$("#d2").append(a);
});
Upvotes: 3
Reputation: 82297
You should use remove
. It will return the elements.
$(function(){
var a = $("#d1").children("a").remove();
$("#d1").html("");
$("#d2").append(a);
});
Upvotes: 3