Can someone explain why the following snippet does not add
to both #a
and #b
?
HTML:
You need to create a new instance
every single time you want to append to the DOM.
Otherwise it refers to the same instance which was already appended.
Remove the $
symbol preceding the new div to be added as that evaluates to a jQuery object and has the limitations as above stated. or clone
the element.
$(function(){
var foo = "HI ";
$("#a").append(foo);
$("#b").append(foo);
});
Check Fiddle