Getting jQuery Mobile checkbox value

I set my checkboxes for mobile jquery like this.

$("#checkbox-2a").attr("checked", settings.DEnabled).checkboxradio("refresh"); 

Here is the markup

  <fieldset data-role="controlgroup" data-mini="true" style="text-align:center;"> <input type="checkbox" name="checkbox-2a" id="checkbox-2a" class="custom" /> <label for="checkbox-2a"> Enable D</label> .. 

Check the boxes correctly. But now that I want to get the value using this code.

  settings.DEnabled = $("#checkbox-2a").attr("checked"); 

When I debug it, it returns "checked" when I look at the markup, although the flags are updated when the correct control bool in ui is correct. I do not see the "checked" attribute in the markup.

How do I get / find the value of this flag?

+6
source share
1 answer

attr does not return a boolean, you can use the prop method: http://api.jquery.com/prop/#entry-examples

 settings.DEnabled = $("#checkbox-2a").prop("checked"); 

Or is :

 settings.DEnabled = $("#checkbox-2a").is(":checked"); 
+14
source

Source: https://habr.com/ru/post/925235/


All Articles