Malik Rizwan Malik Rizwan - 6 months ago 79
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!

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.