At a certain time, there can be many events going on in the browser, like mouse clicks, mouse movements, key presses, among others. We need the browser to wait for a particular event to occur, and after that perform a set of instructions.
Look at the example given below:
In the above example, we are listening to
a few types of events on the
p DOM object using the
This listener method will monitor
the DOM object for a particular event.
addEventListener, we specify the name of the event
the code that we want to execute
once that particular event occurs.
For example, as soon as someone
copies the code from the
we log to the console that data was copied.