New to javascript and I find myself often trying one before realizing the other one is what I need, are they not doing the same thing?
Asked
Active
Viewed 915 times
1 Answers
2
Here are what I found for your questions: addEventListner:
- Can add multiple events to a particular element.
- Can take a third argument that can control the event propagation.
- Can only be added within elements or in external JavaScript file.
On the other hand - onclick:
- Can add only a single event to an element, and it is basically a property, so gets overwritten.
- Event propagation cannot be controlled by onclick.
- Can be added as an HTML attribute also.
Also, you can read more about the difference Here

leonguyen.to
- 36
- 3