I'm building a form that's supposed to hide and show content according to bootstrap-switch selections made by the user. The onclick="documentFilter event works on normal check-boxes; however, the moment I initialise bootstrap-switch, the code does not work as intended. Any idea what I'm missing? Thanks!
<!--DEPENDENCIES-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js"></script>
<!--HTML-->
<body>
<div class="container">
<label>
<input type="checkbox" name="my-checkbox" onclick="documentFilter(this, '#hideableDiv')"> Some caption
</label>
<div id="hideableDiv" class="hiddenByDefault">Some hidable content
</div>
</div>
</body>
<!--PAGE-SPECIFIC SCRIPT-->
<script type="text/javascript">
//Initialise BootstrapSwitch
$("[name='my-checkbox']").bootstrapSwitch();
//Unchecked on load
$(".hiddenByDefault").hide();
//document filter function
function documentFilter(trigger, target) {
var $target = $(target);
$(trigger).change(function () {
$target.toggle(this.checked);
});
}
</script>