javascript - bootstrap switch does not work for dynamically created checkbox input -
i have following combination of scripts : jquery, bootstrap, modernizer, json2html.
calling :
<script> $('#my01switch').bootstrapswitch({ ontext: 'on', offtext: 'off', size: 'large', oncolor: 'success', offcolor: 'warning', labeltext: '*' }); </script>
just before closing body tag, on :
<input name="my01switch" id="my01switch" data-toggle="switch" checked="" type="checkbox">
the above dynamically generated input tag.
please help.
check if document ready before execute bootstrap switch plugin:
$(document).ready(function() { //code });
update switch checkbox code:
add class checkbox
<input name=\"my01switch\" id=\"my01switch\" type=\"checkbox\" data-toggle=\"switch\" checked=\"true\" class=\"custom-box\"/>
update js code:
function renderrooms(json) { if (json !== undefined) { //..... //$('#roomboxwrap').json2html(json, transforms.theroom); $('#form-nav').json2html(json.rooms, transforms.menurooms); $('#title_room_name').append(getroomname(json)); //after rooms loaded $('.custom-box').bootstrapswitch(); } }
Comments
Post a Comment