Bootstrap css not working after ajax refresh

2.3k views Asked by At

I'm using Bootstrap for on/off toggle switch. In this page, it has a ajax refresh of every 5 secs to reload the page content. The problem i'm facing is when the page refresh through ajax, the bootstrap-switch loses its css style.

I use firefox inspect and this is what i saw:

before ajax refresh:

<div id="override">
.....
    <div class="margin-bottom-10">  <label for="option1"></label>  <div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-on bootstrap-switch-small bootstrap-switch-animate bootstrap-switch-id-1234>
                <div class="botstrap-switch-container">
                  <span class="bootstrap-switch-handle-on bootstrap-switch-primary">On</span>
                  <label class="bootstrap-switch-label" for="1234"></label>
                  <span class="bootstrap-switch-handle-off bootstrap-switch-default">Off</span>
                  <input id="1234" name="radio1" class="make-switch" data-size="small" checked="" type="checkbox">
        </div>
        </div>
        </div>
......
</div>

After ajax refresh:

    <div id="override">
    .....
        <div class="margin-bottom-10">  
          <label for="option1"></label>
          <input id="1234" name="radio1" class="make-switch" data-size="small" checked="" type="checkbox">
        </div>
..........
    </div>

ajax code:

$.get(url, function(data) {
  $("#override").html(data);
}

How do i reload those necessary bootstrap css & perhaps even js ??

1

There are 1 answers

0
niksmac On

I assume you are using this

If yes you can do something like

$.get(url, function(data) {
 $("#override").html(data);
 $(".make-switch").bootstrapSwitch(); //code to init the switch again
}