switchery icon indicating copy to clipboard operation
switchery copied to clipboard

Switchery click function doesn't work if the page is ajax loaded.

Open srakshit opened this issue 9 years ago • 4 comments
trafficstars

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

srakshit avatar Nov 29 '15 01:11 srakshit

This is not a switchery issue, you have to load and execute the code separately after u have fetched the html !

Legends avatar Nov 29 '16 16:11 Legends

Could you please explain with examples? I'm having same issues

rgheleribefore avatar Feb 10 '17 17:02 rgheleribefore

There is no documentation how catch a state change with multiple switches. Please explain.

DjustinK avatar Mar 13 '17 09:03 DjustinK

@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.

Legends avatar Mar 13 '17 11:03 Legends