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 7735395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:29:30+00:00 2026-06-01T07:29:30+00:00

I saw this in some code: $(<p/>).append(<div>something</div>).appendTo(body); and noticed that it automatically closed the

  • 0

I saw this in some code:

$("<p/>").append("<div>something</div>").appendTo("body");

and noticed that it automatically closed the p tag in the generated HTML :

<p><div>something</div></p>

I’ve never seen the selector syntax $("<p/>") before. Is this mistake (and Chrome is just guessing what it should be) or is this a feature of jQuery’s selector syntax?

  • 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-06-01T07:29:31+00:00Added an answer on June 1, 2026 at 7:29 am

    The $ function is heavily overloaded, even having two functionalities for strings. If the string is a CSS selector, it will return an object containing the matching elements from the document. If you open with <, it will create the element. jQuery is not creating a tag, however. Elements belong the DOM, tags belong to HTML, which is a serialization of the DOM.

    $("<p/>")  //Creates a p element
        .append("<div>something</div>") //inserts a child element, which is a div you created
                                        //containing the string "something"
        .appendTo("body"); //tags the newly created paragraph element, with its div child
                           //and inserts it into the DOM as a child of the body element.
    

    When you serialize the document, you will wind up with:

    <body><p><div>something</div></p></body>
    

    which shows each element containing its children.


    If your markup looks like this: <p/><div>something</div>, then the p and div elements are siblings. That would happen if they were appended to the same parent:

    //Use add to create a new element and add it to the jQuery collection object
    //instead of appending it as a child to the p element.
    $("<p/>").add("<div>something</div>").appendTo("body");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw some code written by another developer that looks something like this: var
I saw some code on the apple website that goes like this id <NSFetchedResultsSectionInfo>
I was looking at some code and saw something like this: int d =
const static int foo = 42; I saw this in some code here on
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
I saw this same question for VIM and it has been something that I
I hate that google can not search for symbols. I saw this in some
Was recently reviewing some Java Swing code and saw this: byte[] fooReference; String getFoo()
I saw this in some C code: Wininfo W = { sizeof(Wininfo) }; What
I saw this today in some PHP code: $items = $items ?: $this->_handle->result('next', $this->_result,

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.