What is the main difference between of using this:
document.addEventListener('mousedown', function() {
// code
}, false);
…and this?
document.onmousedown = function() {
// code
}
Will there be any different result or any cause?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
onclickis a property, like theonclickattribute can be placed in HTML. It has best browser support, however, it is primitive, as reassigning it overwrites the first (like any object property).addEventListener(), as the name suggests, allows you to register multiple callbacks for an element and event type. This allows you to have multiplemousedownevents for the same element. Before IE9, IE had their ownattachEvent()which is similar (you must specify theonpart too withattachEvent()).