Every time something happens, that's an event. Click an element, that's an event. Hover over
an element, that's an event. When you don't hover over an element, that's still an event.
Want something to happen when some event happens? This is where JavaScript comes in!
Let's not use lists, this time. We'll go over through some of the most commonly used event
types. How the user triggers these event types is pretty much self-explanatory, so instead
we'll also go to the best examples on executing these events.
The first type is onclick, undoubtedly one of the
most dynamic event types. This event is triggered when the user clicks on the element.
The perfect example for using this event type is using sliders, where the parameters are
numbers which affect how far from the left the slider goes. Oh, the format for
calling a function is functionName([parameter]).
That's it; onclick is so dynamic, it can be used for a lot
of many things.
The second type is onmouseenter. This event functions a lot
like :hover, except that it only occurs once the cursor "enters"
an element. A more repetitive version of this event is onmouseover,
where every time you move the mouse within the element, the event occurs. Think of this event
as onclick without the need to click. Anyway, the gist of this is that
onmouseenter function acts like :hover and
is mostly useful when you want to create interactions like lighting up the navigation tab that corresponds
to the position of the cursor on the page.
The third type is onmouseleave which is the opposite of
onmouseenter. The former works similarly to onmouseout,
which is the opposite to onmouseover. Think of both of the outgoing events
as :not(:hover). Normally, when using these types, the effects revert to normalcy,
or not in hover-mode.
The fourth type is onload which triggers actions when the document page is
completely done loading. I recommend using this if you want to randomly generate some content in your page
upon loading.
The fifth and final type I'm going to discuss is onbeforeunload, which is mostly
used to warn the user before leaving the page and going to an outside link.
There are many possibilities in using JavaScript events. Visit
https://www.tutorialspoint.com/ for more information about the topic.
×