I'm using jquery chosen plugin for styling select dom element in my form. And i realize many line of code for my filter in vanila javascript without jquery. But the javascript fails to track the event which is hung on the form when the user selects the data stylized through the plugin in the select. How i can track this event in vanila js?
JS track event
let filterFormArray = document.querySelectorAll('[data-filter*=filter]');
filterFormArray.forEach(function(elem) {
elem.addEventListener('change', function(e) {
filterAjax(filterSerialize(this), e);
});
});
JQ initialization chosen
$(".filter-box select").chosen({
disable_search_threshold: 100,
allow_single_deselect: true,
max_selected_options: 5
});
Well, I did it like this.
let getChosen = document.querySelectorAll('.chosen-results');
if (getChosen.length > 0) {
getChosen.forEach(function(elem) {
elem.addEventListener('click', function() {
filterAjax(filterSerialize(this.closest('form')));
});
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.