HighDots Forums  

edit div content

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss edit div content in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
toto
 
Posts: n/a

Default edit div content - 08-31-2005 , 04:26 AM






hello

is there a way to edit the content of a div ?
for instance to change :

<div>
foo
</div>

into

<div>
ree
</div>

thanks !


Reply With Quote
  #2  
Old   
Kimmo Laine
 
Posts: n/a

Default Re: edit div content - 08-31-2005 , 04:46 AM






"toto" <toto (AT) chaos (DOT) ko> wrote

Quote:
hello

is there a way to edit the content of a div ?
for instance to change :

div
foo
/div

into

div
ree
/div


<div id="foo">
Donald Duck
</div>

<script type="text/javascript">
foo = document.getElementById('foo');
foo.removeChild(foo.childNodes[0]);
var newtext = document.createTextNode("Mickey Mouse");
foo.appendChild(newtext);
</script>

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com




Reply With Quote
  #3  
Old   
toto
 
Posts: n/a

Default Re: edit div content - 08-31-2005 , 04:53 AM



thanks a lot !

I also found that answer here :
http://fr.selfhtml.org/javascript/ob...htm#node_value
(solution for a p tag, but works as well for a div)

thank !!
sorry for asking to quickly...

On Wed, 31 Aug 2005 12:46:15 +0300, Kimmo Laine wrote:

Quote:
"toto" <toto (AT) chaos (DOT) ko> wrote in message
newsan.2005.08.31.09.26.52.315592 (AT) chaos (DOT) ko...
[quoted text muted]

div id="foo"
Donald Duck
/div

script type="text/javascript"
foo = document.getElementById('foo');
foo.removeChild(foo.childNodes[0]);
var newtext = document.createTextNode("Mickey Mouse");
foo.appendChild(newtext);
/script


Reply With Quote
  #4  
Old   
Wayne Dobson
 
Posts: n/a

Default Re: edit div content - 09-01-2005 , 03:27 PM



"toto" <toto (AT) chaos (DOT) ko> wrote

Quote:
hello

is there a way to edit the content of a div ?
for instance to change :

div
foo
/div

into

div
ree
/div

thanks !
First, add an ID for the div element. Then:

document.getElementById("id").firstChild.data = "Changed Text"

--
Wayne
"Aka Dobbie the House Elf."




Reply With Quote
  #5  
Old   
Jasen Betts
 
Posts: n/a

Default Re: edit div content - 10-15-2005 , 05:31 PM



On 2005-08-31, Shawn Wilson <shawnw (AT) dvigroup (DOT) net> wrote:

Quote:
document.all.pens.innerHTML = words;
vs

Quote:
foo.appendChild(newtext);

Quote:
I'm no expert, that's just a way that I found when I was looking to do the
same thing... it seems simpler, but is there anything technically better for
doing it either way?

innerHTML is not part of the standard
(and IME badly supported on IE - sepecially for table elements)

ApopendChild(etc) is part of the standard, and so should work on all
ECMAscript capable browsers.

Bye.
Jasen


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.