1

I have no earlier jQuery mobile experience, and now I am trying to add new checkbox dynamically in javascript.

Using (in html head)

jquery.mobile-1.4.5.min.css
jquery-1.11.3.min.js
jquery.mobile-1.4.5.min.js

part of HTML:

<form>
    <fieldset data-role="collapsible">
        <div id="agree" data-role="controlgroup"></div>
        <input type="submit" value="Submit">
    </fieldset>
</form>

part of JAVASCRIPT:

var html = '<input type="checkbox" name="checkbox-1" id="checkbox-1" /><label for="checkbox-1">I agree</label>'; 
$('#agree').html(html); 
$("input[type='checkbox']").checkboxradio("refresh");

I am getting only plain checkbox, no any formatting. What is wrong? Am I missing something?

M-K
  • 33
  • 1
  • 4
  • Could you please share a working snippet, maybe a JSFiddle, so that we know which version of JQuery you are using? – Naren Murali Oct 15 '17 at 17:23
  • here are some full working examples: [Dynamically creating productlists with checkboxes in jQuery Mobile](https://stackoverflow.com/questions/41325900/dynamically-creating-productlists-with-checkboxes-in-jquerymobile-proves-difficu/41484070#41484070) and here: [Jquery Mobile checkbox-list does not update when adding items and : “refreshing” the script to style it](https://stackoverflow.com/questions/41404047/jquery-mobile-checkbox-list-does-not-update-when-adding-items-and-refreshing-t/41409019#41409019) – deblocker Oct 16 '17 at 07:03

1 Answers1

0

Try this way:

$("[data-role=controlgroup]").enhanceWithin().controlgroup("refresh");

I hope this helps you!

jcarrera
  • 1,007
  • 1
  • 16
  • 23