• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM - remove text question

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a div tag with an id of mainBlock. How can I remove everything inside the DIV tag using DOM and javascript? Thanks.

Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
document.getElementById('mainBlock').innerHTML = "";
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or....

Iterate through all the children removing each from the parent.

The former is easier and liklely quicker.
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,
Thanks that worked fine. I thought for sure I had tried that though earlier and then (after thinking it failed) started trying other things. Anyways thanks again.

Rob
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DOM way



Eric
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That div tag I was talking about. Sometimes it may or may not be on the page what is the easiest/best way to determine it's on the page or not? Thanks.

Rob
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry guys. I had a typo in the if statement.

Rob
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic object detection


Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic