Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 774863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:11:56+00:00 2026-05-14T19:11:56+00:00

Why this $(#mydiv).append(<ul>); $(#mydiv).append(<li>Hello</li>); $(#mydiv).append(</ul>); alert($(#mydiv).html()); produces <ul></ul><li>Hello</li> and not <ul><li>Hello</li></ul> ? Thanks!

  • 0

Why this

$("#mydiv").append("<ul>");
$("#mydiv").append("<li>Hello</li>");
$("#mydiv").append("</ul>");
alert($("#mydiv").html());

produces

<ul></ul><li>Hello</li>

and not

<ul><li>Hello</li></ul>

?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:11:57+00:00Added an answer on May 14, 2026 at 7:11 pm

    Because the browser needs to (re)build its DOM after each append. It can’t know that a closing tag will come later, and an opening tag by itself is invalid, so error correction kicks in which in this case closes the unclosed element.

    This is one of the reasons why innerHtml and things that rely on it (such as jQuery’s append method) are not reliable and should be avoided when possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a page like this: <html> <head> <style type=text/css> #mainDiv{ height: 100%; } #myDiv{
Let's say, I've got this. <div id = myDiv> <% Html.RenderPartial(MyUserControl); %> </div> and
Lets say I have an empty div: <div id='myDiv'></div> Is this: $('#myDiv').html(<div id='mySecondDiv'></div>); The
I have created an element like this: var myDiv = new Element('div'); myDiv.update('Hello!'); I
I am adding textboxes dynamically to a div. Something likhe this $('#xyz').click(function() { $(#myDiv).append('<textarea></textarea>');
Is there a difference between ... this <html> ... <div id=myDiv> </div>'; ... </html>
On this fiddle http://jsfiddle.net/adrianjsfiddlenetuser/zyUkd/46/ the divs 'Hello 01' & 'Hello 02' fire an alert
I can make a obj to use the canvas to draw like this: MyObj.myDiv
I got this bad feeling about how I insert larger amounts of HTML. Lets
Could someone explain why the alert statement would return nothing when used in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.