Re: Change the same span element all the time
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Change the same span element all the time

From: Ronaldo Junior <setembro@gmail.com>
Date: Fri Apr 28 2006 - 19:52:32 CEST

David wrote:
> I'd really appreciate any help. Im trying to change a label over and
> over again. I can change it the first time, by using the following
> code, however it never works again, how can i do this so it uses the
> same element name? This is driving me insane. On the second call to var
> spanElm = document.getElementById("FirstNameLengthLabel"); spanElm is
> set to NULL.
>
> <script language=javascript>
>
> function txtFirstNameUpdate()
> {
> var para = document.getElementById("ForenameCell");
> alert (para);
> var spanElm = document.getElementById("FirstNameLengthLabel");
> alert (spanElm);
> var newSpan = document.createElement("FirstNameLengthLabel");
> alert (newSpan);
> var newText = document.createTextNode("Next label");
> alert (newText);
> newSpan.appendChild(newText);
>
> var test = para.replaceChild(newSpan,spanElm);
> }

It won't work twice because the replaceChild method actually replaces
the node, erasing it to give place to the other one to replace to.
Therefore, the first node won't exist after the first call.

I'd suggest something but I didn't figure what you're trying to do.
Received on Mon May 1 05:25:52 2006