1
<div class="ui-checkbox">
      <input type="checkbox" value="1" name="reminder" id="reminder" checked="">
      <label for="reminder" class="ui-btn ui-corner-all ui-btn-inherit ui-btn-icon-left ui-checkbox-off ui-last-child">Reminder</label>
</div>

I am generating the above css and input checkbox on runtime via jquery however my checkbox isn't selecting could someone help me.

I have tried everything using jquery mobile and nativedroid

enter image description here

13
  • How come label has type?? Commented Jul 1, 2014 at 14:20
  • because i need to add css before that in case of checkbox so made that i can change it to some other identifier Commented Jul 1, 2014 at 14:22
  • I don't understand how a label can be of type checkbox... Commented Jul 1, 2014 at 14:24
  • have removed it doesn't really effect my outcome Commented Jul 1, 2014 at 14:24
  • @vini - now you're talking. Commented Jul 1, 2014 at 14:25

3 Answers 3

3

For dynamic checkboxes in jQuery Mobile, you need to initialize the widget either by calling .checkboxradio() on the input or .enhanceWithin() on the container, e.g.:

var chk = '<label><input type="checkbox" name="checkbox-0 ">Check me</label>';    
$("#dynCheck").empty().append(chk).enhanceWithin();

This assumes you have a container with id="dynCheck", and you want to empty it before adding the dynamic content.

<div id="dynCheck"></div>

Here is a DEMO

Sign up to request clarification or add additional context in comments.

Comments

0

How are you generating the above content? I think that's more relevant than the content itself. When creating and checking checkboxes via jQuery, you should use the prop() method to actually check the created boxes.

For example:

$('#reminder').prop('checked', true);

Comments

0

Your HTML markup just needs to define a checkbox wrapped in a label (or a label using the "for" attribute). jQueryMobile will do the rest, including checking/unchecking. You do not need to define any classes, such as ui-radio, ui-btn, etc.

<label>
   <input type="checkbox" name="checkbox-0 ">Check me
</label>

Documentation: http://demos.jquerymobile.com/1.4.2/checkboxradio-checkbox/

Example: http://jsfiddle.net/3awV7/

2 Comments

It doesn't work because my html is being generated dynamically in jquery mobile
I'm not sure I understand what you mean. Are you defining the checkbox via javascript and appending it to the page?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.