innerHTML expected behavior?
- gumOnShoe
-
gumOnShoe
- Member since: May. 29, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (15,244)
- Block
-
- Forum Stats
- Member
- Level 15
- Blank Slate
Hey, doing some web programming.
I'm using innerHTML to change the look of my page. I suppose I ought to learn the insert & remove dom element functions, but I was just going with what I knew and I started recognizing unusual behavior. Wasn't sure if it was Chrome or if it was expected.
If I have the following:
<div id="container">
<div id="blah1"/>
<div id="blah2"/>
<div id="blah3"/>
</div>
Then, when I do:
document.getElementById('blah2').innerHTML="Some Random Text";
Rather than just changing that element, I find that it wipes out everything in the element AND everything after it. The above would give me:
<div id="container">
<div id="blah1"/>
<div id="blah2">Some Random Text</div>
</div>
Notice that blah3 dissapeared. Again, I was just wondering if this was expected. It seems like a bug to me, but I've seen it a few times and I'm new to this so maybe I'm just crazy and expect too much.
- gumOnShoe
-
gumOnShoe
- Member since: May. 29, 2004
- Offline.
-
- Send Private Message
- Browse All Posts (15,244)
- Block
-
- Forum Stats
- Member
- Level 15
- Blank Slate
At 9/19/11 03:38 AM, BUCHANKO wrote: Just for the record...
You cannot self enclose <div> tags, they should be properly closed with a </div>
Yeah i figured that out last night... a bit weird, but ok.
Thanks. That fixed the issue.


