I would like to dynamically switch the state of a Zurb Foundation Switch control using javascript.
This is the default Zurb Fondation switch:
<div class="switch"> <input id="d" name="switch-d" type="radio" checked> <label for="d" onclick="">Off</label> <input id="d1" name="switch-d" type="radio"> <label for="d1" onclick="">On</label> <span></span> </div>
Demo is here . I believe that they are based on this project .
When I tried to change the state of the switch using jquery:
$('#d1').attr('checked','checked'); $('#d').removeAttr('checked'); // Switch ON $('#d').attr('checked','checked'); $('#d1').removeAttr('checked'); // Switch OFF
It worked in Firefox, but not in Chrome. In Chrome [v25 on OSX10.8.3], the first command - Enable - succeeds, but when I try to use $('#d').attr('checked','checked'); $('#d1').removeAttr('checked'); $('#d').attr('checked','checked'); $('#d1').removeAttr('checked'); , then it looks like CSS incorrectly selects the element as checked, and on-screen transitions - see how the last switch in the image below does not display the OFF state.

You can check these commands on the Switch page of the Zurb Foundation documentation; d refers to the fourth and largest switch that you see in the list at the top of the page.
source share