Search code examples
jqueryjquery-mobileflipjquery-mobile-flipswitch

jquery mobile - change flip switch default state


I'm using jQuery mobile's flip switch and by default the switches are off. I can't figure out how to set the default value to 'ON'

<form id="sound-switch">
        <select name="flip-3" id="snd-switch" data-role="flipswitch" data-mini="true">
        <option value="off">Off</option>
        <option value="on">On</option>
    </select>
</form>

I read somewhere to add value="on" to the html but I can't get it to work. Does anyone have any experience with this?


Solution

  • Try

    Added selected="selected" to On so that it is selected when it page loads.

    By default always first option is selected

    <option selceted="selected" value="on">On</option>
    

    Fiddle Demo

    <form id="sound-switch">
        <select name="flip-3" id="snd-switch" data-role="flipswitch" data-mini="true">
            <option value="off">Off</option>
            <option selected="selected" value="on">On</option>
        </select>
    </form>
    


    Check here http://validator.w3.org/check

    SELECTED is not a member of a group specified for any attribute

    using SELECTED will work but not pass w3 says invalid :)

    use selected="selected"