Idan Shechter Idan Shechter - 6 months ago 308
Javascript Question

Changing a Switchery checkbox state from code

How do I programatically change a jQuery Switchery checkbox state from checked to unchecked (and vice versa)?

I tried using

global_switch_sound.prop('checked', true)
on the checkbox element but it doesn't work.

HTML:

<input id="sound-active-input" type="checkbox" />


JavaScript:

global_switch_sound = new Switchery(document.querySelector('#sound-active-input'));

Answer

Try this:

$('.switchery').click();

It should trigger a click and switch. OR this:

$('.switchery').trigger('click');
Comments