Should preventDefault be used only on anchor tags?
E.g do I need to add preventDefault to a select?
$(".select").onchange(function(e) {
e.preventDefault();
var value = $(this).attr('value');
window.location = '?filter=' + value;
});
You only need to use
preventDefaultwhen there is some default behaviour that you want to prevent.Changing the value of a select element doesn’t have any default behaviour.
Clicking a link does. Submitting a form does too. (This is not an exhaustive list)
You might want to run some JavaScript when a link is clicked, and still follow the link.
There is no hard and fast rule for when you use
preventDefaultbeyond when there is some default behaviour that you want to prevent.