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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:34:08+00:00 2026-06-12T21:34:08+00:00

I’m wondering if there is a difference in performance (or what is the best

  • 0

I’m wondering if there is a difference in performance (or what is the best practice) in creating DOM elements with jQuery.

By my knowlegde there are 3 ways to do this:

  1. By string:

    $('<a href="http://www.example.com" class="footerLink" rel="external">example</a>');`
    
  2. Create element first, add attributes later:

    $('<a></a>')
      .addClass('footerLink')
      .attr({ 
         rel: 'external, 
         href: 'http://www.example.com' 
      })
      .text('example');
    
  3. Create element and pass attributes object with it:

    $('<a></a>', {
      'class': 'footerLink', 
      href: 'http://www.example.com',
      rel: 'external'
    })
    .text('example');
    

EDIT:
What if you are appending a lot of items to an element? Should you make a very long string first and append that after the loop?

  • 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-12T21:34:10+00:00Added an answer on June 12, 2026 at 9:34 pm

    The fastest way for you to be to create the entire DOM you want to attach as string and then attach it to the document as html():

    var dom = '<a href="http://www.example.com" class="footerLink" rel="external">example</a>';
    $(element).html(dom);
    

    Of the three that you have in your example the fastest should be the 3rd one, for the reason that it does not have to do any complex string parsing and the attributes are not put using chained function calls but are provided as a single object as a parameter to the selector.

    There is a forum thread on jQuery you may want to check out.

    Update:

    If you are creating a lot of items to an element, then you should definitely take the string approach. Take a look at the following example of making a 1000 list elements.

    // Assume we have data defined with 1000 data members
    // each containing a text property
    var list = [];
    for (var i = 0; i < data.length; i++) {
        list.push('<li>' + data.text + '</li>');
    }
    $(ul).html(list.join(''));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.