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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:16+00:00 2026-05-21T04:01:16+00:00

Is there a way to quickly build out a set of elements in jQuery?

  • 0

Is there a way to quickly build out a set of elements in jQuery? I know I can $('<div>').addClass('name'); a ton of times with .append() to create something like the example bellow but I was wondering if there is a better way to do it.

<div class="navBox">
    <div class="topLeft"></div>
    <div class="topRight"></div>
    <div class="bottomLeft"></div>
    <div class="bottomRight"></div>
    <div class="hBar">
        <div class="leftTab"></div>
        <div class="rightTab"></div>
        <div class="buttonLeft">
            <div class="leftArrow"></div>
            <div class="leftBar"></div>
        </div>
        <div class="buttonRight">
            <div class="rightArrow"></div>
            <div class="rightBar"></div>
        </div>
    </div>
    <div class="vBar">
        <div class="topTab"></div>
        <div class="bottomTab"></div>
        <div class="centerTab"></div>
        <div class="buttonTop">
            <div class="topBar"></div>
            <div class="topArrow"></div>
        </div>
        <div class="buttonBottom">
            <div class="bottomArrow"></div>
            <div class="bottomBar"></div>
        </div>
    </div>
</div>

Update: I know I can brute force create it, I was hoping for something like jQuery building it for me based on a mark up like Zen-Coding or some such thing. I hoping to not have to include the block of HTML in code.

  • 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-21T04:01:17+00:00Added an answer on May 21, 2026 at 4:01 am

    It depends if the content is going to be dynamic or not.

    If static, just put the HTML in a single JS string and append using:

    $('something').html(allMyHtml);
    

    If you prefer to keep the HTML in your HTML file (makes sense), then you can make use of a <script type="x-myTemplate"> block:

    <script id="myTemplate" type="x-myTemplate">
       <p>All my HTML goes in here</p>
    </script>
    

    … and then retrieve the HTML using $('#myTemplate').html(). Any content placed inside a <script> block with an unknown type attribute won’t be rendered by the browser.

    If dynamic, you can use the same method as above, but with jQuery’s templating engine.

    You may also be interested in the lesser-known shorthand for creating elements in jQuery:

    $('<p>', {
        class: 'something',
        id: 'Blah',
        text: 'Hello'
    });
    // Produces: <p class="something" id="Blah">Hello</p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way in .NET to quickly get the current protocol, host,
is there way thats i can preselect an item when the page loads or
Is there a way to find the name of the program that is running
Is there a way to quickly collapse all function definitions in the Flash Builder
Is there any way to quickly import data from a .csv or tab delineated
Is there a way to quickly search for the complete list of code paths
In Java is there any way of writing a loop so that you can
I would like to know if is there any way to increase the sample
Is there way in next piece of code to only get the first record?
Is there a way to enforce constraint checking in MSSQL only when inserting new

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.