What is the difference between DOM Level 0 events vs DOM Level 2 events? I ask because I was told that Firefox and IE call them in a different order and I had never heard those terms before.
What is the difference between DOM Level 0 events vs DOM Level 2 events? I ask because I was told that Firefox and IE call them in a different order and I had never heard those terms before.
Share Improve this question edited Mar 26, 2021 at 22:49 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 12, 2011 at 23:07 Jonathan AllenJonathan Allen 70.3k77 gold badges270 silver badges455 bronze badges2 Answers
Reset to default 13DOM Level 0 events were based around the concept of using element attributes or named events on DOM elements, e.g.:
<input type="button" onclick="clickMe();" />
Or
input.onclick = function() { ... };
With DOM Level 2, we've now got a more standardised approach to managing events and subscriptions, with addEventListener
, removeEventListener
, etc.
You can read more here here
It wasn't until IE8 that Microsoft added support for the W3C standard for event management to their browser. Not sure in what order they are called....
In addition to the issue that previous answer mentioned pletely and correctly, which concentrated on the type of using event handlers to call functions or to perform some other JavaScript(I mean using inline registration model and traditional registration model vs using addEventListener(...), removeEventListener(...), or dispatchEvent(...) ) and also to add additional information to this duplicated question, there is another great difference between DOM Level 0 vs DOM Level 2 event model.
Through DOM Level 2 event model, it is simply possible that a specific object(for example via: document.getElementById("elementId")), with a specific event(one of click or load, ...) can be registered any number of event-handler functions. For example:
<!DOCTYPE html>
<html>
<body>
<button id="btn">Test it</button>
<script>
document.getElementById("btn").addEventListener("click", function(){alert("first alert");});
document.getElementById("btn").addEventListener("click", function(){alert("second alert");});
</script>
</body>
</html>
This was one of the problems in DOM Level 0, which is handled via other solutions.