I’m using an old school jQuery code to modify elements that has true/false attributes such as checked
or selected
. This appears to be not working when I tried it on jQuery mobile checkbox. I used a different method instead and it works so far without investigation why my old method does not work.
My old code goes like this.
// To check $("#some_checkbox").attr("checked", "checked").checkboxradio("refresh"); // To uncheck $("#some_checkbox").removeAttr("checked").checkboxradio("refresh");
This method, for some reason does not work for me in jQuery mobile (simulated in a desktop browser). I saw a sample in docs and tried to use it and it works flawlessly.
// To check $("#some_checkbox").prop("checked", true).checkboxradio("refresh"); // To uncheck $("#some_checkbox").prop("checked", false).checkboxradio("refresh");
Note that this may require higher version of jQuery. However, using:
$("#some_select").attr("selected", "selected").selectmenu("refresh");
works for select/dropdown elements. Weird.
I haven’t investigated further but there must be something wrong with my old code. Too lazy to investigate though.
Good Post! Thx
Super really helped me. Thanks a lot
Nice post,Thanks.
Thanks!! Its really helping.
Just had to thank you after many hours of frustrating checkbox coding fails!
Great ! I was getting mad with these checkboxes not displaying the new state.