Article:
  Dynamic Content with DOM-2 (Part I of II)
Subject:   The quick brown fox...
Date:   2005-04-27 12:42:27
From:   normalforce
I have noticed something interesting. When I click on the "call replaceSpan()" button the first time and have the fox jump ontop of the astounded zebra I don't get any Javascript errors. However, the next time I click on it, I get an uncaught exception error on the line that with the replaceChild method.


This is the same problem I have when I have two buttons trying to make the fox do different things. The first button successful writes the text while the second yields the aforementioned error.


Am I missing something? Should the variables be cleared before trying to write another textNode to the span? I can't figure out what I am doing wrong.

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • The quick brown fox...
    2005-04-27 13:16:48  normalforce [View]

    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!