I need to dynamically create a Switchery switch.
I'm creating non-dynamic switches like this:
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Admin User</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="checkbox" class="js-switch" id= "canModify"/>
</div>
</div>
And this works just fine.
However when I create the same structure via JavaScript like this:
html = '<input type="checkbox" class="js-switch" id= "' + elementID + '"/>'
I get these results:
The one below was statically added, and it appears correctly. The one above generated dynamically, but it appears only as a check box. So my question is, how do I solve this?

Simply adding a new input to the DOM with
class="js-switch"will not create a Switchery-style switch.A JavaScript Switchery object must be created for each input.
This function will convert all non-switchery inputs in the DOM to Switchery-style switches:
A working example:
References: