jquery - Bootstrap toggle button fires multiple change events -
im having issues getting bootstrap togglebutton work (http://www.bootstraptoggle.com/). added toggle button follows
<input type="checkbox" checked data-toggle="toggle" data-on="redigér" data-off="deaktivér" data-onstyle="danger" data-offstyle="primary" id="aktiv_toggle">
the button used disabling/enabling elements inside fieldset.
when clicking toggle button handle change event follows:
$(function() { $('#aktiv_toggle').change(function() { alert("test"); if ($(this).prop('checked')) { $("#aktiver").prop("disabled", true); } else { $("#aktiver").prop("disabled", false); } }) })
put alert in there verify multiple change event (sometimes not always). can't figure have done wrong?
bonus info: it's random how many times change event fired. once, other times 2 or 3 times.
update (problem has "changed"): toggle button resides inside php file loaded content div using ajax. if remove togglebutton style , script import php file , put head of index alongside other styles , scripts togglebutton works fine. necessary, put imports of css , scripts inside head of index. not possible load includes dynamically depending on page load div ?
Comments
Post a Comment