Search code examples
javascripthtmlcsscheckboxswitchery

Add view checkbox with same class (Switchery)


I tried to add into my website view checkboxes with js-switch class. This code use Switchery module. I wrote my example below:

<pre><code>http://codepen.io/Rootka/pen/bpvbNy</code></pre>

How to add a view checkboxes with same class - e.g. "js-switch"?


Solution

  • With querySelectorAll() you can do the following to active your switches:

    var elem = document.querySelectorAll('.js-switch');
    for(var i = 0; i < elem.length; i++ ){
        new Switchery(elem[i], {className:"switchery"});
    }
    

    Your now working codepen: http://codepen.io/kbkb/pen/dMmbvK