Results 1 to 13 of 13

Thread: [RESOLVED] JavaScript innerHTML Problem

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] JavaScript innerHTML Problem

    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).
    Last edited by Slyke; Dec 11th, 2008 at 09:14 AM.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    What is the complete code?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    This code here will produce the same problem:

    Code:
    <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.

    The code that I'm doing it in is a bit long to send.

    By the way, I'm using Firefox v3.

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    I don't quite understand what it is you are trying to do whether you want:

    1. Just have the opening <ul> tag.

    or

    2 Have the alert display the text within the <ul> tags?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    I want to have just an opening <ul> tag inside theMenuSection.

    But for some unknown reason, if you place in a <ul> tag, it also automatically closes the <ul> tag. Run the sample code I placed up and you will see what I mean.

    I need the tag to remain open so that I can have another javascript function create a nested <ul> tag inside the parent one (For a nested list).

    Basically, I need the HTML inside theMenuSection, to be what I want it to be, not having a </ul> in it, like is being placed in. So option 1.

    Now, I really have no idea why it auto-closes the tag, and why on earth the developers would make it do this.

    I need either an alternative (Something other then innerHTML), or a solution (Maybe a parameter somewhere)?
    Last edited by Slyke; Dec 11th, 2008 at 02:03 AM.

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    Code:
    <html>
    <span id="testspan"></span>
    <br />
    <script>
    var theMenuSection
    theMenuSection=document.getElementById("testspan");
    theMenuSection='<ul>'; 
    alert(theMenuSection);
    </script>
    </html>
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    Actually, wait.

    That don't work. If you do that, then theMenuSection no longer refers to the span/div tag.
    Last edited by Slyke; Dec 11th, 2008 at 09:13 AM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    I mean, you can no longer refer to the span/div tag. So how can this be achieved (The auto-completing turned off)?

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    Try using the right or left function to subtract the length tag from that of innerHTML.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    I already did that, but it still puts it there (It must put it there when it actually writes it to the webpage).

    Maybe it's not possible, sooo... is there any other thing I can use to place html onto the page?

  11. #11
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    Quote Originally Posted by Slyke
    I already did that, but it still puts it there (It must put it there when it actually writes it to the webpage).

    Maybe it's not possible, sooo... is there any other thing I can use to place html onto the page?
    Just a thought have you disabled the "code hints" in your html editor (if possible)?

    Edit:

    Code:
    <html>
    <span id="testspan"></span>
    <br />
    <script>
    var theMenuSection
    theMenuSection=document.getElementById("testspan");
    theMenuSection.html='<ul>';
    alert(theMenuSection.html);
    </script>
    </html>
    Last edited by Nightwalker83; Dec 12th, 2008 at 07:57 AM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: JavaScript innerHTML Problem

    You're a genius! That worked a charm .

    Can't disable "code hints" because this is going in an instruction manual for some online software (Everyone reading it would have to disable it right?).

  13. #13
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: JavaScript innerHTML Problem

    Quote Originally Posted by Slyke
    You're a genius! That worked a charm .

    Can't disable "code hints" because this is going in an instruction manual for some online software (Everyone reading it would have to disable it right?).
    For some reason not sure why the following happen:

    Code:
    .html = open tag
    .innerHTML = <ul></ul>
    .outerHTML = <span id="testspan"></span>
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width