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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:01:43+00:00 2026-05-24T20:01:43+00:00

How do I write an html select statement via jquery? Let’s say I’ve got

  • 0

How do I write an html select statement via jquery?

Let’s say I’ve got this in mind:

<select id="mySelect">
  <option value="400">400</option>
  <option value="401">401</option>
  <option value="402">402</option>
  <option value="403">403</option>
</select>

And I need it to be written from jquery.

I’ve tried this (without success)

$('#div2').append('<select name = "myshield2" id="myshieldSelect2">');
var i = 400;
while (i < '410') {
   // do some code
   $('#div1').append('<option name="asdf" value = "1">Hey ' + i + ' is the value!</option>');
   i++;
}
$('#div2').append('</select>');
  • 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-24T20:01:44+00:00Added an answer on May 24, 2026 at 8:01 pm

    When using append jQuery appends the actual html elements instead of the html, its not like writing to a stream of HTML.

    Also, appending to HTML attached to the document itself in small parts is extremely inefficient. The following variation of your code should work and should be much faster:

    var html = [];
    html[html.length] = '<select name = "myshield2" id="myshieldSelect2">';
    var i = 400;
    while (i < '410') {
       // do some code
       html[html.length] = '<option name="asdf" value = "1">Hey ' + i + ' is the value!    </option>';
       i++;
    }
    html[html.length] = '</select>';
    $('#div1').append(html.join(''));
    

    Here’s an example of it in action: JSBin Example

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

Sidebar

Related Questions

this is my code <html:select property=singleSelect> <html:option value=0>Select One </html:option> <script type=text/javascript> var nfhEvents
Take the below HTML select for an example: <select name=selValues id=selValues> <option value=1>One</option> <option
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
I want to use php array for HTML select list. In this case it
I'm trying to write up the LINQ statement that is equivalent to: select e.EmployeeID,
I want to write Html format, but I can not even get a simple
How can we write html tidy coding only for inserting closing tag in the
I have a requirement to write HTML to the file system and I was
Code: <% using (Ajax.BeginForm(GetResourcesByProject, CreateRequest, new AjaxOptions { UpdateTargetId = ResourceListDiv})) { Response.Write(Html.DropDownList(SelectProject, Model.ProjectList,
I'm looking to write a html sanitiser, and obviously to test/prove that it works

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.