Forum Moderators: open

Message Too Old, No Replies

Deleting Tag Contents

Deleting <div> Contents in Javascript (XHTML)

         

Quasaur1

7:15 pm on Nov 6, 2004 (gmt 0)

10+ Year Member



What's the easiest way to delete the contents of a tag (like <div>) from javascript?

whoisgregg

7:17 am on Nov 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure what you mean, do you want your page to have a div and a link to erase that div's contents? This code accomplishes that:

<div id="remove_me">The user can click something to make me disappear.</div>
<a href="#" onclick="document.getElementById('remove_me').innerHTML = '';">Delete Above</a>

<edit>typos, typos, typos</edit>

Quasaur1

2:22 am on Nov 8, 2004 (gmt 0)

10+ Year Member



Gregg:

Thanks for replying...

You're right: i wish to erase the contents of a <div> and fill the tag with other info (imported XML data).

I will test the code you gave me...

...will it work in IE6 as well?

whoisgregg

8:14 pm on Nov 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



imported XML data

Here's a couple of silly questions: Are you trying to replace div contents in your own pages before you upload them to your site? Or are you trying to let the user change the content on the page while they browse?

Quasaur1

3:50 am on Nov 10, 2004 (gmt 0)

10+ Year Member



i amtrying to let the user change the content on the page while they browse.

whoisgregg

10:00 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The method I posted is correct then, you still need to get the data. I assume you've got an XMLHttpRequest to get the data. I don't know anything about that part of it, but whatever you grab goes into a variable, then you just assign the .innerHTML of the div to equal that variable:
var newContents = ''; 
document.getElementById('changingDiv').innerHTML = newContents;