js innerHTML problem

Discussion in 'Web Design, HTML And CSS' started by conradbf, Nov 3, 2009.

  1. conradbf

    conradbf New Member

    Joined:
    Nov 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a function that takes the innerhtml from a div called orderouterwrap, generates some new content called str, and then writes the new string to orderouterwrap. However, it adds on spurious closing divs (</divs>) at the end for no reason.

    starting markup:

    <div id="orderouterwrap">
    <!-- -->
    </div>

    JS:
    new_str=document.getElementById('orderouterwrap').innerHTML;
    new_str+=str;

    alert(new_str);

    OUTPUT START:
    <!-- -->
    <div class="orderwrp" id="order0">
    <div class="name">stuff<div>
    </div>
    OUTPUT END

    document.getElementById('outerorderwrap').innerHTML=new_str;

    alert(document.getElementById('outerorderwrap').innerHTML);

    OUTPUT START:
    <!-- -->
    <div class="orderwrp" id="order0">
    <div class="name">stuff<div>
    </div>

    </div></div>
    OUTPUT END

    What on earth is going on?

    thanks in advance,
    Conrad
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    Because there's a mistake in the first output itself,

    <div class="orderwrp" id="order0">
    <div class="name">stuff<div> <-------- the last div in this line should be a closing tag
    </div>

    so to close all the tags, it's adding 2 more div close tags
     
    SaswatPadhi likes this.
  3. conradbf

    conradbf New Member

    Joined:
    Nov 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    oh dear, its been one of those days..

    that did it, thanks!
     
  4. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    :welcome:
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice