Is there some jquery magic that will let me do the following:
[0- define some element in HTML (eg, a unchecked checkbox)]
1- update its DOM element by s
Just remove the element from the document and keep a reference to it. There's no need to clone it.
var el;
function removeEl() {
el = $("#myElement")[0]; // Get the element itself
el.parentNode.removeChild(el);
}
function reinsertEl(node) {
node.appendChild(el);
}
As an aside since you mentioned it in your example, it's much simpler, clearer and faster to set the checked
property of a checkbox directly rather than use attr()
. There's no need to involve attributes at all and indeed jQuery's attr()
usually doesn't. Just do $("#myElement")[0].checked = true;
. It works in all mainstream browsers.