Search code examples
jquery-mobilejquery-mobile-flipswitch

How to get the value of a checkbox flipswitch in JQuery Mobile 1.4.5?


I'm using following markup to create a checkbox-based Flipswitch in jQuery Mobile 1.4.5:

<label for="flip-1">Checkbox Flip switch:</label>
<input data-role="flipswitch" name="flip-1" id="flip-1" type="checkbox">

Apparently, the same method to get the value for a select-based Flipswitch:

$("#flip-1").val()

is not working with the checkbox-based version, and i'm getting always the value of "on".

What i'm doing wrong here? Is there a way to get the value as for the select-based version?

Fiddle: http://jsfiddle.net/2ckHr/296/

Thanks in advance


Solution

  • Instead of reading .val() read the checked property:

    alert($("#flip-1").prop("checked"));
    

    Updated FIDDLE