Web Analytics Made Easy -
StatCounter Are <div>s considered a text node in a DOM - CodingForum


No announcement yet.

Are <div>s considered a text node in a DOM

  • Filter
  • Time
  • Show
Clear All
new posts

  • Are <div>s considered a text node in a DOM

    I am just starting to learn DOMs so that I can alter my page with javascripts. I am reading that text nodes can not have children. I am confused by two things. What is considered a text node? In the example from the brainjar website they call <p id="sample1"> blah blah </p> a text node. Is <div id="sample">blah blha </div> a text node?

    I use <div> to contain all my text. If <div> is a text node in that case, then doesn't nested <div>s mean the nested <div> is a child. For example:

    <div id="parent">
    <div id="child">blah</div>

    Doesn't the parent node have a child node in this case? or are <div>s handled differently. Again I am a newbie, but I am trying to learn as much, and as fast as possible.

  • #2
    You misunderstood what brainjar said

    The text node in

    <p id="sample1"> blah blah </p>

    is the text "blah blah", not including the <p>. That text node is the child of the element p.

    Read again what brainjar pointed in his sample code:

    <p id="sample1">Initial text within a paragraph element.</p>

    ... code to add a text node ...

    var text = document.createTextNode(" new text " + (++counter1));
    var el = document.getElementById("sample1");
    vBulletin Mods That Rock!