The mouseover()
method triggers the mouseover
event when the mouse pointer is over a selected element. It is a short-hand of the on('mouseover', eventHandler)
event.
This method is triggered with the selected element even when the mouse pointer enters any child element.
$(selector).mouseover(function());
This method accepts only one parameter that is a function invoked when triggered by the mouseover()
method.
Let’s look at the code below:
In the HTML tab:
div
with id="content"
.jQuery
script.In the JavaScript tab:
mouseover()
method on the element with the id of content (i.e., "#content"
).css()
method to change the background color of that element (i.e., "#content"
) when mouseover()
is invoked.randomColor
, that generates a random color and returns it.The mouseover()
method is invoked once we move the mouse pointer over the square. As a result, the background color of the square changes.