Search code examples
twitter-bootstrapbootstrap-switch

bootstrap-switch is not loading


i have include all the dependencies and i still cannot figure out why it doesn't give me the switch that i want. Am i missing something ? Also i can't get the the post data when i click on my save changes button.

<link href="bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap-switch/css/bootstrap3/bootstrap-switch.css" rel="stylesheet">
<script> src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script src="bootstrap-switch/js/bootstrap-switch.js"></script>

<h2 class="h4">State</h2>
<div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-id-switch-modal bootstrap-switch-animate bootstrap-switch-on" style="width: 102px;">
  <div class="bootstrap-switch-container" style="width: 150px; margin-left: 0px;">
    <span class="bootstrap-switch-handle-on bootstrap-switch-primary" style="width: 50px;">ON</span>
    <span class="bootstrap-switch-label" style="width: 50px;">&nbsp;</span>
    <span class="bootstrap-switch-handle-off bootstrap-switch-default" style="width: 50px;">OFF</span>
    <input id="switch-modal" type="checkbox" checked="">
  </div>
</div>
<button type="button" class="btn btn-primary" data-switch-get="state" data-dismiss="modal">Save changes</button>


Solution

  • First of all correct your jQuery script from:

    <script> src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    

    To:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    

    According to Bootstrap Switch documentation:

    You only need to include your input:

    <input id="switch-modal" type="checkbox" checked>
    

    And initialize it in JavaScript like this:

    $('#switch-modal').bootstrapSwitch();
    

    CODEPEN EXAMPLE