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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:10:25+00:00 2026-05-15T11:10:25+00:00

Lets say I have an empty div: <div id=’myDiv’></div> Is this: $(‘#myDiv’).html(<div id=’mySecondDiv’></div>); The

  • 0

Lets say I have an empty div:

<div id='myDiv'></div>

Is this:

$('#myDiv').html("<div id='mySecondDiv'></div>");

The same as:

var mySecondDiv=$("<div id='mySecondDiv'></div>");
$('#myDiv').append(mySecondDiv);
  • 1 1 Answer
  • 1 View
  • 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-15T11:10:26+00:00Added an answer on May 15, 2026 at 11:10 am

    Whenever you pass a string of HTML to any of jQuery’s methods, this is what happens:

    A temporary element is created, let’s call it x. x’s innerHTML is set to the string of HTML that you’ve passed. Then jQuery will transfer each of the produced nodes (that is, x’s childNodes) over to a newly created document fragment, which it will then cache for next time. It will then return the fragment’s childNodes as a fresh DOM collection.

    Note that it’s actually a lot more complicated than that, as jQuery does a bunch of cross-browser checks and various other optimisations. E.g. if you pass just <div></div> to jQuery(), jQuery will take a shortcut and simply do document.createElement('div').

    EDIT: To see the sheer quantity of checks that jQuery performs, have a look here, here and here.


    innerHTML is generally the faster approach, although don’t let that govern what you do all the time. jQuery’s approach isn’t quite as simple as element.innerHTML = ... — as I mentioned, there are a bunch of checks and optimisations occurring.


    The correct technique depends heavily on the situation. If you want to create a large number of identical elements, then the last thing you want to do is create a massive loop, creating a new jQuery object on every iteration. E.g. the quickest way to create 100 divs with jQuery:

    jQuery(Array(101).join('<div></div>'));
    

    There are also issues of readability and maintenance to take into account.

    This:

    $('<div id="' + someID + '" class="foobar">' + content + '</div>');
    

    … is a lot harder to maintain than this:

    $('<div/>', {
        id: someID,
        className: 'foobar',
        html: content
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have hierarchy like this (This is just a test program. Please
Lets say I have one table called REVIEWS This table has Reviews that customers
Let's imagine that I have something like this: <html> ... <div> <iframe src=test.html hash=r4d5f7></iframe>
Lets say I have a 3 column <table> or <div> with widths of 50%
Lets say I have the following Request URI: /controller/action/filter// When I call $this->_getParam('filter') in
Lets say I have this XML: <images> <photo> <thumbImg>images/thumbs/002.jpg</thumbImg> <filename>002</filename> </photo> <photo> <thumbImg>images/thumbs/008.jpg</thumbImg> <filename>008</filename>
Lets say I have a set of model classes like this: public class Person
This one is driving me crazy:-) Lets say I have some test xaml code:

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.