minhur / bootstrap-toggle

Bootstrap Toggle is a highly flexible Bootstrap plugin that converts checkboxes into toggles
http://www.bootstraptoggle.com
MIT License
1.48k stars 440 forks source link

addEventListener does not work #199

Closed vincent-olivert-riera closed 5 years ago

vincent-olivert-riera commented 5 years ago

When I use addEventListener to call a function on change event, it does not work. However, if I use jQuery's .on('change', ...) it does work. Why is that?

This is my code:

<html>
<head>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- Bootstrap 3 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Bootstrap-Toggle -->
<link rel="stylesheet" href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
</head>
<body>
<input data-toggle="toggle" type="checkbox" id="mytoggle">
<script>
document.querySelector('#mytoggle').addEventListener('change', () => alert('hello'));
/* this one works
$('#mytoggle').on('change', () => alert('hello'));
*/
</script>
</body>
</html>
vincent-olivert-riera commented 5 years ago

Duplicate of https://github.com/minhur/bootstrap-toggle/issues/178