6

Possible Duplicate:
JavaScript: remove element by id

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

3
  • if you dont want to use javascript because parent nodes then you should use jquery Commented Jun 18, 2012 at 10:04
  • 3
    @shareef jQuery uses parent nodes. jQuery is just a javascript function, you know. Commented Jun 18, 2012 at 10:18
  • stackoverflow.com/questions/15759882/… Commented Nov 2, 2015 at 14:44

2 Answers 2

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 );
Sign up to request clarification or add additional context in comments.

1 Comment

Actually I am tring to remove the div elements of Google Hangouts Page, while loading my application.
22

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

4 Comments

+1 for showing how easy it's done with jQuery, even though the OP didn't ask for it. )
@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.
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.
I'm using $("#another-media["+data.id+"]").remove(); but it doesn't work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.