Similar to this question, I'm trying to prevent the scrollwheel form incrementing a numeric input.
In Chrome/webkit, the following works but in Firefox the wheel still changes the input.
$('input[type=number]').on('mousewheel',
function(e){ $(this).blur(); }
);
<script src=".1.1/jquery.min.js"></script>
<input type="number">
Similar to this question, I'm trying to prevent the scrollwheel form incrementing a numeric input.
In Chrome/webkit, the following works but in Firefox the wheel still changes the input.
$('input[type=number]').on('mousewheel',
function(e){ $(this).blur(); }
);
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number">
Share
Improve this question
asked Dec 11, 2017 at 19:36
JosiahJosiah
3,1781 gold badge35 silver badges47 bronze badges
2 Answers
Reset to default 6Yeah, it doesn't work with firefox. This should work though :) Hope it helps.
$('input[type=number]').on('wheel', function(e){
return false;
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="menu">
I've found a better solution using vanilla Javascript:
document.querySelectorAll("input[type=number]").forEach(function (element) {
element.addEventListener("wheel", function(event) {
if (document.activeElement === event.target) {
event.preventDefault();
}
});
});