Jump to content

JavaScript innerHTML Problem


Recommended Posts

Why does

Code:

theMenuSection.innerHTML='<ul>';

alert(theMenuSection.innerHTML);

Produce

Code:

<ul> </ul>

?

This is very annoying since the list has a child list inside it and is constructed as the page is loading. Is there any way to prevent JavaScript from closing off the <ul> tag?

theMenuSection is a div tag (also tried span).

Use this code to reproduce the problem:

<span id="testspan"></span>

<br />

<script>

var theMenuSection

theMenuSection=document.getElementById("testspan");

theMenuSection.innerHTML='<ul>';

alert(theMenuSection.innerHTML);

</script>

Copy paste it into a text file, and rename to htm, and open it.

By the way, I'm using Firefox v3, but I'm sure it does it in IE too.

Link to comment
Share on other sites

As I mentioned earlier, I know not much about JavaScript.

What I would do in your situation would be to find the most comprehensive JavaScript reference on the Internet, then see if there is any option like 'noclose' or so. Also look for sample scripts in the many tutorials that are around.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy