开发者

Remove a dom element from the document, but save it as a variable?

Is there a way to remove a dom element from the document, but save it as a variable? I'm guessing I have to save the clone as a var, and then remove the original?

Also, w开发者_高级运维ould such a technique store styles etc?


Yes, that's what you do.

var savedElement = document.getElementById('element_that_you_want_to_save');
savedElement.parentNode.removeChild(savedElement);

// savedElement will still contain the reference to the object,
// so for example, you can do:
savedElement.style.height = '100px';
document.getElementById('container').appendChild(savedElement);
// etc.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜