5

Possible Duplicate:
JavaScript: remove element by id

I only know their respective ids and don't know specifically about their parent nodes....

Community
  • 1
  • 1
NOVICE TANUJ
  • 59
  • 1
  • 1
  • 3

2 Answers2

28

You can use parentNode on the element to get its parent, and use removeChild on it.

var el = document.getElementById( 'id' );
el.parentNode.removeChild( el );
Florian Margaine
  • 54,552
  • 14
  • 89
  • 116
22

In jQuery, just $('#your_id').remove(); will work.

xdazz
  • 154,648
  • 35
  • 237
  • 264
  • 2
    +1 for showing how easy it's done with jQuery, even though the OP didn't ask for it. ) – raina77ow Jun 18 '12 at 10:04
  • 3
    @raina77ow your statement says the following "congratulations for promoting a certain project" and "the OP didn't mention being able to use this library but what the heck +1 none the less". In other cases answers that require an external library that wasn't specifically asked for or accepted as a possibility by the op are downvoted. – Mihai Stancu Jun 18 '12 at 21:25
  • 1
    Well, in my environment it's always beneficial to use some library instead of writing your own code - unless one has **very** strong reasons not to do so. Besides, I suppose the OP just begins to learn JavaScript: in that case studying jQuery as well will save him a LOT of time - as this answer clearly shows. If you want him to reinvent the wheel instead, good luck. – raina77ow Jun 18 '12 at 21:34