admin管理员组文章数量:1318976
IE's removeNode (VS.85).aspx
helps me to decide whether I would like to remove childNodes or not.
I would like to know whether the same exists for Firefox, Opera, Chrome and Safari. If not, how can I achieve it?
IE's removeNode http://msdn.microsoft./en-us/library/ms536708(VS.85).aspx
helps me to decide whether I would like to remove childNodes or not.
I would like to know whether the same exists for Firefox, Opera, Chrome and Safari. If not, how can I achieve it?
Share Improve this question asked Dec 21, 2010 at 2:21 NazmulNazmul 7,21812 gold badges53 silver badges64 bronze badges2 Answers
Reset to default 5Didn't want just just copy code over, give this a read: http://www.sitepoint./forums//showthread.php?p=947385
Edit (but I, pst, have no shame -- code from above link ;-)
if ( window.Node )
Node.prototype.removeNode = function( removeChildren )
{
var self = this;
if ( Boolean( removeChildren ) )
{
return this.parentNode.removeChild( self );
}
else
{
var range = document.createRange();
range.selectNodeContents( self );
return this.parentNode.replaceChild( range.extractContents(), self );
}
}
No, .removeNode()
is not a standard method and it does not exist outside IE.
If you are looking for removeNode
's functionality of promoting element's children up a level (an optional boolean argument), you have to do it manually.
However, with jQuery it is easy:
$(elToRemove).replaceWith($(elToRemove).children());
本文标签: javascriptWhat is the equivalent of IE39s removeNodeStack Overflow
版权声明:本文标题:javascript - What is the equivalent of IE's removeNode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742055840a2418288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论