Setting Div Value (nodes problem)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ace214
    New Member
    • Apr 2007
    • 5

    #1

    Setting Div Value (nodes problem)

    Ok so I have researched this problem and am confused. What I want do is have a caption in a <div> under a picture be changable. So I have this:

    Code:
    <div id="Caption" style="color: rgb(51,51,102); font-family: Verdana; font-size: 90%; text-align: center"></div>
    <script type="text/javascript"> //Set Caption- use abs to avoid array error with three digit variable
    document.getElementById("Caption").childNodes[0].nodeValue = Captions[Math.abs(i)];
    </script>
    But it only works in FF if I put a space in the original <div> and it doesn't work in IE at all. Don't get it. What do I need to do?
    The full page is here.

    Thanks for any help.
  • basstradamus
    New Member
    • Mar 2007
    • 11

    #2
    Hi,
    Try that

    <script type="text/javascript"> //Set Caption- use abs to avoid array error with three digit variable
    if (document.getEl ementById("Capt ion").firstChil d) document.getEle mentById("Capti on").firstChild .nodeValue = Captions[Math.abs(i)];
    else document.getEle mentById("Capti on").appendChil d(document.crea teTextNode(Capt ions[Math.abs(i)]));
    </script>


    And remove that white space from div, leave it "empty".
    Additionaly, please remember that FF treats all new-line signs as nodes so if have for instance div:
    <div class="example" >
    <div></div>
    <div></div>
    </div>

    that div (example) has 5 childNodes in FF in IE it has 2.

    Comment

    • ace214
      New Member
      • Apr 2007
      • 5

      #3
      Ok, that worked, thanks for the help. Although, I think I'm just gonna make the div contain one letter- it's easier than making it process the if. Thanks again.

      Comment

      Working...