The interaction between JavaScript and HTML is handled via events that occur when the user or the browser manipulates a page. An event occurs when a webpage loads. When a user hits a button, it triggers an event. Other instances include pressing any key, closing or resizing a window, and so on.
Js reacts to these events when javascript code is embedded in HTML and allows execution. Event Handling refers to the process of reacting to occurrences. As a result, JavaScript uses Event Handlers to handle HTML events.
Event handlers are the JavaScript code that invokes a specific piece of code when a particular action happens on an HTML element. The event handler can either invoke the direct JavaScript code or a function.
Only when an event occurs in the context of the object on which they are registered are event listeners called. The button node is given a handler in this example. Clicking the button activates the handler, but clicking anywhere else in the document does not. Adding a onclick attribute to a node has a similar effect.
Using addEventListener, add an event handler to each of the div tags ().
Double-check that the event is "click" here.
The method addEventListener() takes three parameters.
Learner's Ratings
4.8
Overall Rating
82%
17%
0%
1%
0%
Reviews
S
Sachin
5
most useful to begginar
M
Master Peace
5
best
S
Sunny
5
I really liked the way of explaining.
M
M Abdullah
5
Very Nice!
P
pratima nice mall
5
good explaining
B
Bikramjit singh
5
Very helpful to web development
M
Mohammad Arif
5
very helpful for beginners
A
Ankit Singh
5
good
R
Rajendra Deshmukh
5
Thank you for providing a valuable and well-managed session
Share a personalized message with your friends.