I implementing a sorting_by mechanism on a woocommerce website.
I have dynamically created a select
element with option
s and their value
are set to the url with the parameters.
I then added the jQuery events on click
to do a simple window.location.href
to the url.
The code within the jQuery event does not execute at all in Chrome but works perfectly fine in Firefox.
I have tried moving to vanilla JS for that and it still isn't working.
Here is what I have so far:
jQuery('.sorting_filt option').on('mousedown touchstart click', function (e) {
let url = $(this).val();
console.log(url);
window.location.href = url;
});
The redirection is happening correctly in Firefox.
In Chrome not even the Console.log()
is happening.
CodePudding user response:
This makes it work
$(document).ready(function () {
jQuery('.sorting_filt option').on('mousedown touchstart click', function (e) {
let url = $(this).val();
console.log(url);
window.location.href = url;
});
});
CodePudding user response:
Replacing
jQuery('.sorting_filt option').on('mousedown touchstart click',function(){});
with
jQuery('.sorting_filt').on('change', function(){...}
makes it work on both browsers while the first ONLY works on firefox.