Jonh Smid Jonh Smid - 2 years ago 97
Javascript Question

How to check "checkbox" dynamically - jQuery Mobile

With HTML a checkbox is created like this:

<input type="checkbox" id="category1">Category1<br>

With javascript we can check the checkbox like this:

$("#category1")[0].checked = true

Now I am trying to create the same page with jquery-mobile. The checkbox looks like this:

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

Why is there is no
here? Is the name the
? Should I delete the attribute name and create one with the name

How can I check this checkbox here with Javascript/jQuery?

I tried the code above, but it doesn't seem to work for this checkbox.

Answer Source

You need to refresh it after changing its' .prop, using .checkboxradio('refresh'). This is the correct way to check checkbox/radio in jQuery Mobile.


$('.selector').prop('checked', true).checkboxradio('refresh');

Reference: jQuery Mobile API

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download