Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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() {
  switchery.disable();
});

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

on creating new switchry it can be set disable but in other event it doesn't work switchery.disable(); 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!

like image 389
Malik Rizwan Avatar asked Nov 19 '25 08:11

Malik Rizwan


1 Answers

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

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

https://jsfiddle.net/63kamhss/1/

like image 171
Ashok kumar Avatar answered Nov 21 '25 22:11

Ashok kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!