"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why is the onchange Event Not Triggered for Range Input Drag in Firefox?

Why is the onchange Event Not Triggered for Range Input Drag in Firefox?

Published on 2024-11-19
Browse:525

Why is the onchange Event Not Triggered for Range Input Drag in Firefox?

Firefox onchange Event Not Triggered on Range Input Drag

In input elements with type "range," when the slider is dragged, the onchange event is only triggered when the slider is dropped to a new position in Firefox. In contrast, Chrome and other browsers trigger onchange events during the drag.

Solution: Use oninput Event

Firefox correctly triggers the onchange event only upon release, as per the specification. To capture live updates during dragging in all browsers, use the oninput event instead.

function showVal(newVal){
    document.getElementById("valBox").innerHTML=newVal;
}

Combining oninput and onchange for Cross-Browser Compatibility

For cross-browser compatibility, consider combining both oninput and onchange event handlers:


This ensures that onchange events are still triggered in Firefox upon release, while oninput events provide continuous updates in all browsers.

Release Statement This article is reprinted at: 1729506736 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3