Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Web Design, HTML And CSS Forums (http://www.go4expert.com/forums/web-design-forum/)
-   -   js innerHTML problem (http://www.go4expert.com/forums/js-innerhtml-problem-t19975/)

conradbf 3Nov2009 21:36

js innerHTML problem
 
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').innerHTM L=new_str;

alert(document.getElementById('outerorderwrap').in nerHTML);

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

nimesh 3Nov2009 23:33

Re: js innerHTML problem
 
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

conradbf 4Nov2009 00:08

Re: js innerHTML problem
 
oh dear, its been one of those days..

that did it, thanks!

nimesh 4Nov2009 00:12

Re: js innerHTML problem
 
:welcome:


All times are GMT +5.5. The time now is 22:02.