最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dom - Javascript: document.removeElementById? - Stack Overflow

programmeradmin2浏览0评论

Assuming I have an element called menu how would I remove this element from the page? Is there a document.removeElementById function? or something equivalent?

Assuming I have an element called menu how would I remove this element from the page? Is there a document.removeElementById function? or something equivalent?

Share Improve this question asked Mar 3, 2011 at 13:00 SkizitSkizit 44.9k93 gold badges213 silver badges270 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

No direct mand but this will do what you need:

var element = document.getElementById("menu");
element.parentNode.removeChild(element);

You can wrap it nicely with function if you want. :)

This should work?

document.removeChild(menu);

Or

menu.parentNode.removeChild(menu);
发布评论

评论列表(0)

  1. 暂无评论