Malik Rizwan Malik Rizwan - 3 years ago 341
Javascript Question

Disable Switchery onclick

i want to disable switchery but failed i did try difrent code from here this code doesn't work for me

var elem = document.querySelector('.js-dynamic-state');
var switchery = new Switchery(elem);

document.querySelector('.js-dynamic-disable').addEventListener('click', function() {

document.querySelector('.js-dynamic-enable').addEventListener('click', function() {

on creating new switchry it can be set disable but in other event it doesn't work
it displays error in console

disable is not function

i also did try this which generates new switchery

var switchery = new Switchery(elem, { disabled: true });

when i use the above given code completely in that event it generates new switchery button.

any help!

Answer Source
var elem = document.querySelector('.js-switch');
var init = new Switchery(elem);

Use the above code to disable() function the disable the element. or enable() function to enable the element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download