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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:14:18+00:00 2026-05-30T01:14:18+00:00

I really dont like writing something like $(‘body’).append(‘<div class=foo>foo</div>’); Because i usually end up

  • 0

I really dont like writing something like

$('body').append('<div class="foo">foo</div>');

Because i usually end up with a quite messy string.

I prefer doing something like

var $div = $('<div/>').attr({ 'class' : 'foo' }).text('foo');
$('body').append($div);

Someone told me that the last option is a lot slower, performance-wise. So i would like some input from you guys. Is there a difference? Which way do you prefer?

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-30T01:14:21+00:00Added an answer on May 30, 2026 at 1:14 am

    The second method is very noticably slower in most web browsers.

    Basically the first method can pass the string to .innerHTML and let the web browser do its thing in native code, whereas the second method has to invoke a lot of separate JS methods, each of which in turn calls some native function in the web browser to make an adjustment.

    For a small example, such as that shown there is almost no noticable difference – but if you profile adding, say 1000 rows to a table using each method, you will notice a significant difference in time taken – particularly on the slower browsers.

    In fact, using the second method with any significant amount of elements on IE 8 or lower tends to lock up the browser for some time.

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

Sidebar

Related Questions

As a developer I really don't like writing documentation but when I have to
Ive decided that I really dont like microsoft and their ways. Please could you
My way of writing stuff looks something like this - I have a colorcolumn
I'm writing a quick server app for something so don't really want to write
I am writing this because I have really no idea why this is happening.
I really don't like the VS2008 Start Page. I don't need the RSS reader,
I am re-designing an application for a ASP.NET CMS that I really don't like.
I currently use JPA annotations only, but I really don't like that I'm polluting
So, I've been playing with asp:PasswordRecovery and discovered I really don't like it, for
GWT seems like a really nice technology for Java developers who don't like (or

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.