addeventlistener javascript onchange code example
Example 1: javascript add function to onchange event
transport_select.setAttribute("onchange", function(){toggleSelect(transport_select_id);});
transport_select.onchange = function(){toggleSelect(transport_select_id);};
Example 2: handling event changes
<button>Click me any way you want</button>
<script>
let button = document.querySelector("button");
button.addEventListener("mousedown", event => {
if (event.button == 0) {
console.log("Left button");
} else if (event.button == 1) {
console.log("Middle button");
} else if (event.button == 2) {
console.log("Right button");
}
});
</script>