What is the difference between DOM 0 and DOM Level 2 events?

What is the difference between DOM 0 and DOM Level 2 events? I ask because I was told that Firefox and IE call them in a different order, and I have never heard these terms before.

+3
source share
2 answers

DOM level 0 events were based on the concept of using element attributes or named events on DOM elements, for example:

<input type="button" onclick="clickMe();" /> 

or

 input.onclick = function() { ... }; 

With DOM Level 2, we now have a more standardized approach to managing events and subscriptions using addEventListener , removeEventListener , etc.

Here you can read here here

Only in IE8 did Microsoft add support for its W3C event management standard to its browser. Not sure what order they are called ....

+7
source

In addition to the fact that the previous answer is mentioned completely and correctly, the focus was on the type of use of event handlers to call functions or to execute some other JavaScript (I mean using the built-in registration model and the traditional registration model against using addEventListener ( ...), removeEventListener (...) or dispatchEvent (...)), as well as adding additional information to this duplicate question , there is another big difference between DOM Level 0 and DOM Level 2.

Within the framework of the DOM level 2 event model, it is simply possible that a specific object (for example, via: document.getElementById ("elementId")) with a specific event (with one click or loading ...) can be registered with any number of event handler functions. For instance:

 <!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 through other solutions .

+1
source

Source: https://habr.com/ru/post/1233811/


All Articles