switchery
switchery copied to clipboard
Switchery click function doesn't work if the page is ajax loaded.
Hi,
I'm loading a page using ajax which contains the below code.
$(document).ready(function () {
var elems = document.querySelectorAll('#widget-list .js-switch_3');
var switcher;
var switches = [];
for (var i = 0; i < elems.length; i++) {
switcher = new Switchery(elems[i], { color: '#1AB394', size: 'small' });
switches.push(switcher);
}
})
The switches render properly but the switch click function doesn't work. So I can't change the state of the switches.
Thanks Subham
This is not a switchery issue, you have to load and execute the code separately after u have fetched the html !
Could you please explain with examples? I'm having same issues
There is no documentation how catch a state change with multiple switches. Please explain.
@DjustinK
There is no documentation how catch a state change with multiple switches.
It's just a simple checkbox and you can query it the usual way:
$(".js-switch").on("change",function(){alert($(this).is(":checked"));});
<input type="checkbox" class="js-switch" checked />
@rgheleribefore I tried it, and it works.