This article mainly introduces the differences between dom0-level events and dom2-level events in JS, which are of great reference value. I would like to share with you the script home platform for your reference.
Dom0-level events
Go back to above to activateVar btn = $ ('# hash '). get (); btn. onclick = function () {alert ('') ;}; btn. onclick = function () {alert ('');};
For example, if the onclick is written in the tag above, all events are dom0-level events, and fn and fn1 are executed in sequence. The second method obtains elements and binds the onclick event to dom0-level events. The second method overwrites the first onclick event, it will also overwrite the onclick in the row, and only 222 will pop up.
Dom2 events
$ ('# Hash '). click (function () {alert ('first dom2 level of jq')}); $ ('# hash '). click (function () {alert ('second dom2 level of jq')}); btn. addEventListener ('click', function () {alert ('native dom2 level first click')}, false); btn. addEventListener ('click', function () {alert ('second native dom2 click')}, false)
All of the above bindings belong to the dom2-level event binding. The first two are jq binding methods, which are followed by native js binding methods and will not be overwritten, jq binding methods and native binding methods will be executed in sequence, which is at the dom0 level;
Coexistence of dom0 and dom2
Go back to above to activate