Home:ALL Converter>What is the difference between these ways of attaching events?

What is the difference between these ways of attaching events?

Ask Time:2012-07-07T02:39:29         Author:Oxed Frederik

Json Formatter

  1. <div id="myDiv" onclick="MyFunc()"></div>

  2. document.getElementById("myDiv").onclick = MyFunc;

  3. document.getElementById("myDiv").addEventListener("click", MyFunc, false)

Now, what is the difference between these 3 ways of attaching an event to a DOM element (ignoring the fact that 3 won't work on IE)?

Author:Oxed Frederik,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11367887/what-is-the-difference-between-these-ways-of-attaching-events
yy