I have a select menu that is using the select2 plugin. I am trying to add a class to the <select>
element when a menu option is clicked, but it doesn't seem to be working as expected even after testing with an alert.
https://jsfiddle.net/ysm4qhof/1/
$(document).ready(function(){
$('.select2-results__option').on('click', function(){
alert("Hello! I am an alert box!");
});
});
I attempted to click on the ul element as well, but still encountered issues.
$(document).ready(function(){
$('.select2 .select2-results__options').on('click', function(){
alert("Hello! I am an alert box!");
});
});
Although everything seems correct, it's not functioning as intended. What could I be missing here?