Is there a shortcut for:
var child = $('<span>error message</span>');
$('#parent').html(child.html());
or, the same
var child = $('<span>error message</span>');
$('#parent').empty().append(child);
EDIT: above example won't work if I try to assign same child to multiple parents, my child object can only belong to a single parent (which is not what I wanted in my case).
I do realize I could do:
$('#parent').html('<span>error message</span>');
but I want to reuse child object.
EDIT: again, this won't work, since child is a DOM object and can only be placed under at most one parent at any time.
I am looking for something like:
var child = $('<span>error message</span>');
$('#parent').content(child);
childobject then you'll need to keep a reference to it so no, there is no shorter way than you're already doing.empty().append(...)and.html(child.html())are too verbose (exhibit unnecessary details superfluous to my intentions). Plus.html(child.html())feels suboptimal (reconstruct-deconstruct HTML)empty().append().html(content)on an element will simply overwrite anything that was in there in the first place, no need to use empty