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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:28:58+00:00 2026-05-27T02:28:58+00:00

I have the following HTML: <div id=dynamicRadioButtons> </div> Using jQuery I’d like to append

  • 0

I have the following HTML:

<div id="dynamicRadioButtons">



</div>

Using jQuery I’d like to append a radio button with corresponding label to the above div. An example of the HTML I’d like to append is as follows:

<input type="radio" id="dynamicRadio" name="radio" /><label for="dynamicRadio">My Label</label> <br>

So, lets say I have a function that’s called when I click something and takes the parameters id (which is the id of the radio button to be created) and labelText (which is the text of the label to be created), I want to be able to do something like this:

function OnClick(id, labelText){

    // create a new radio button using supplied parameters
    var $newRadioBtn = $('<input />').attr({type="radio", id=id, name="radio"});

    // create a new radio button using supplied parameters
    // TODO - set the value of the label to parameter: labelText
    var $newLabel = $('<label />').attr({for=id});

    // TODO - append the new radio button and label to the div and then append <br>...
    $('#dynamicRadioButtons').append(/* The elements I want to append */);    
}

Can someone help me with my TODO bits please? I was following an example as per this page but just don’t know enough about jQuery to add the label etc. Also is this the best way to dynamically add HTML elements?

  • 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-27T02:28:59+00:00Added an answer on May 27, 2026 at 2:28 am

    You can wrap your label around the form element, which means you don’t have to be quite so verbose.

    <label><input type="radio" id="dynamicRadio" name="radio" />
        My Label
    </label>
    <br />
    

    And you can create it like this:

    function OnClick(id, labelText) {
    
        // create a new radio button using supplied parameters
        var newRadio = $('<input />').attr({
            type: "radio", id: id, name: id
        });
    
        // create a new radio button using supplied parameters
        var newLabel = $('<label />').append(newRadio).append(labelText);
    
        // append the new radio button and label
        $('#dynamicRadioButtons').append(newLabel).append('<br />');
    }
    

    I have used the supplied id for the name and id, otherwise all radios would have a name of “radio”. You might also want to rename OnClick as there are build in event handlers called onclick and it might cause confusion.

    Here is an example JS Fiddle

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

Sidebar

Related Questions

I have the following HTML: <div id=mydiv> </div> I would like to load content
I have the following HTML DIV which does not work using FadeIn in IE:
I have the following html: <div class=bf_form_row> <label for=findout>Text goes here</label> <textarea class=findOut cols=40
I have the following html: <div id=box> <span>stuff.....</span> </div> What i'd like to do
I have the following HTML <div> <label for=username>Username:</label> <input type=text name=username id=username /> <span>some
I have the following html snippet: <div id=contentX><h1>MyHeading1</h1></div> I could select with jQuery snippet
I have following HTML where hover grows div downwards but I would like to
i have following html structure. <p class=expandableContent ><span class=label>Computer and Laptop Repairs</span></p> <div style=clear:
I have the following html: A div, which contains a label and a drop
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a

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.