switchery
switchery copied to clipboard
Duplicating switcherry when the checkbox added dynamically
Hi Guys, Please check the below issue, when i added row dynamically the older checkbox getting duplicated. Here is the code im using when add button clicked -
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch2')) elems.forEach(function(html) { var switchery = new Switchery(html); });
@abpetkov Please suggest me how can i avoid that duplication issue. Thanks,
+1
You need to check that it has not already be instantiated. You can check for the presence of the switchery data element. Something like:
elems.forEach(function(html) {
if(!html.getAttribute('data-switchery')){
var switchery = new Switchery(html);
}
}
I believe this check should be built-in.
Works fine this solution. Thanks bro..