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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:21:36+00:00 2026-05-30T21:21:36+00:00

I am trying to dynamically add some content to a list of checkboxes in

  • 0

I am trying to dynamically add some content to a list of checkboxes in an collapsible <li> item in jQuery Mobile. I cannot get the proper formatting with the nice rounded corners and the grouped items. It gets even worse when I add other elements at the leaf level.

Here is an example that shows the problem (add jquery and jquerymobile scripts and CSS in the header obviously):

<body> 
 <div data-role="page" id="page">
  <ul id="listList" data-role="listview">
   <li id="list1" data-role="collapsible">
    <h3>list 1</h3>
    <div data-role="fieldcontain">
     <fieldset data-role="controlgroup" id="fs1">
      <input type="checkbox" id="cb1" /><label for="cb1">text</label></fieldset></div></li>
   <li id="list2" data-role="collapsible">
    <h3>list 2</h3>
     <p>here comes another list of checkboxes...</p></li></ul>
 <input type="button" onclick="addCheckbox();" value="add a checkbox to list1" /></div>
</body>
<script>
 function addCheckbox() {
   $("#list1 fieldset").append('<input type="checkbox" id="cb2" /><label for="cb2">More text</label>');
 }
</script>

I tried to add .page() after the call to append()but it did not work properly though a bit better.

Beyond my example, the generic question is how to dynamically append content to the DOM tree after jQuery Mobile has played around with the DOM structure. I believe there exists a function that “jquerymobilizes” part of the tree but I cannot find it.

Thanks a lot for your help!

EDIT: In short, I am trying to dynamically add elements into one <li>element of the listview and not trying to add elements to the list itself. Refreshing the listview does not seemt o help here.

EDIT 2: I am getting a bit closer as I found the .trigger("create") function that can be chained to .append() (cf JQM FAQ). With the following script it works slightly better though the data-role="controlgroup" does not provide the right formatting with nice rounded boxes.

$("#list1 fieldset").append('<input type="checkbox" id="cb2" /><label for="cb2">More text</label>').trigger("create");

I will post the full answer if I get there at some point.

EDIT 3: Here is my example illustrated in jsFiddle

  • 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-30T21:21:38+00:00Added an answer on May 30, 2026 at 9:21 pm

    I think I could answer my own question so here is what I got:

    • to dynamically add elements in jQuery Mobile use .trigger("create") (cf. jQuery Mobile FAQ)
    • to add them to the collapsible part of a collapsible element add it to div.ui-collapsible-content or create a div container within the collapsible part ex ante so you add the content directly there
    • to get the nice rendering of grouped checkboxes, you should add all the checkboxes at once (I could not get the sleek rounded corners when I added them sequentially

    So here is my final script that does what I needed:

    $("#list1 div[data-role='fieldcontain']").append('<fieldset data-role="controlgroup">'
        +'<input type="checkbox" id="cb1" /><label for="cb1">text</label>'
        +'<input type="checkbox" id="cb2" /><label for="cb2">More text</label></fieldset>'
        +'<a href="index.html" data-role="button" data-icon="delete">Delete</a>')
        .trigger("create");
    

    I hope it helps!

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

Sidebar

Related Questions

Him I'm trying to add a jQuery tooltip to a dynamically generated list, the
Im trying to add a div tag dynamically with some data attributes but the
I am trying to get a new dynamically created row to add to a
I have a page that I am trying to dynamically add some links to.
I'm trying to dynamically add a validation rule to some dynamic controls: $(input[id*=Hours]).rules(add, required);
I'm trying to dynamically add some hyperlinks to a RichTextBox using WPF and C#
I am trying to dynamically add items to a list adapter using an alert
I'm trying to dynamically add items into a <ul> via jquery, and have followed
I am trying to find a way to dynamically add image with some hover
I'm trying to add some vales to a NSMutableDictionary dynamically. However, using the following

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.