ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button
  Dynamic Content with DOM-2 (Part I of II)
Subject:   The quick brown fox...
Date:   2005-04-27 13:16:48
From:   normalforce
Response to: The quick brown fox...

Don't you just love it when you post a question and then figure it out through a random chain of events about 5 minutes later...

The problem was, after changing the content the first time, the newSpan was never assigned a value of the old id. Thus when you run the function again,

var spanElm = document.getElementById("ex3Span");

returns a null because ex3Span doesn't exist anymore. To get around that, just assign newSpan the old id, as so:

newSpan.id = spanElm.id;

Now it works like a charm!