Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Dom Level 0 Events Vs Dom Level 2 Events?

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 ter

Solution 1:

DOM Level 0 events were based around the concept of using element attributes or named events on DOM elements, e.g.:

<inputtype="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....

Solution 2:

In addition to the issue that previous answer mentioned completely 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><buttonid="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.

Post a Comment for "What Is The Difference Between Dom Level 0 Events Vs Dom Level 2 Events?"