Be a Supporter!

innerHTML expected behavior?

  • 285 Views
  • 1 Reply
New Topic Respond to this Topic
gumOnShoe
gumOnShoe
  • Member since: May. 29, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
innerHTML expected behavior? 2011-09-18 21:51:23 Reply

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.


Newgrounds Anthology? 20,000 Word Max. [Submit]

Music? Click Sig:

BBS Signature
gumOnShoe
gumOnShoe
  • Member since: May. 29, 2004
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to innerHTML expected behavior? 2011-09-19 07:08:20 Reply

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.


Newgrounds Anthology? 20,000 Word Max. [Submit]

Music? Click Sig:

BBS Signature