This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes DOM - remove text question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "DOM - remove text question" Watch "DOM - remove text question" New topic
Author

DOM - remove text question

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
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

Joined: Jan 10, 2002
Posts: 61995
    
  67

document.getElementById('mainBlock').innerHTML = "";


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61995
    
  67

or....

Iterate through all the children removing each from the parent.

The former is easier and liklely quicker.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
DOM way



Eric
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 828
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

Joined: Apr 09, 2002
Posts: 828
Sorry guys. I had a typo in the if statement.

Rob
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Basic object detection


Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOM - remove text question