I am using multiple Bootstrap 4 switches loaded onto the page by JS append and need to call a function on the switch changes. The following example works when I add the switches in HTML, but when I dynamically load them via JS after page load, it will not work.
I DO NOT want to use any other external library for this!
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1">
<label class="custom-control-label" for="customSwitch1">Toggle this switch element</label>
</div>
I have tried multiple JS code, but none seems to be working. Example
$('.custom-control').on('change', function (e) {
let value = this.value;
let test = $(e).target.checked;
});
Also tried using the class of the input tag.