Make sure you download the js file of the bootstrap-toggle file and the css file correctly. In particular, check that they are in the place where your links are listed, or even use the cdn versions listed below:
<link href="https://gitcdn.imtqy.com/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet"> <script src="https://gitcdn.imtqy.com/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js"></script>
Your paths must be incorrect or you forgot to include the js file as a whole, and you should see a warning about this in your console, because otherwise the code works fine.
Regarding dynamically loaded content.
The first elements work because after html first loads, bootstrap-toggle.min.js looks for any elements that have the data-toggle="toggle" attribute and calls .bootstrapToggle() on them using the plugin. This only happens when the page loads.
If you add more switches later, you need to initialize them yourself through .bootstrapToggle() . Iv'e updated the example below to simulate adding speakers dynamically and explain the approach I would take for this. See comments in the code for more details.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link href="https://gitcdn.imtqy.com/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script src="https://gitcdn.imtqy.com/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js"></script> <div class="panel panel-primary" id="switchespanel"> <div class="panel-heading"> <h3 class="panel-title">Switches</h3> </div> <div class="panel-body"> <table class="table"> <tr> <th>Location</th> <th>State</th> </tr> <tr> <td>Testswitch0</td> <td><label> <input type="checkbox" data-toggle="toggle" data-onstyle="success" id="S0" data-size="mini"> </label></td> </tr> <tr> <td>Testswitch0</td> <td><label> <input type="checkbox" data-toggle="toggle" data-onstyle="success" id="S1" data-size="mini"> </label></td> </tr> </table> </div> </div>
source share