X

LATEST #JQUERY NEWS

How to Use jQuery’s .mouseover() Method


jQuery’s .mouseover() method is used to execute some jQuery code whenever an element is “moused-over” (or, as the action is perhaps more commonly referred to, hovered upon). Really, the concept isn’t much different from jQuery’s .hover() method or CSS’s :hover effect, and .mouseover() can be used more or less interchangeably with them.

The syntax for .mouseover() is similar to the syntax of many jQuery event methods. The mouseover is the trigger event, and the code that’s within mouseover’s callback function is the result of the mouseover taking place. As an example, let’s say that when the mouse is moved over an h1 element, you want the color to change to blue. Here’s how that would look:

$("h1").mouseover(function(){
   $(this).css("color", "blue");
})

The biggest difference between using jQuery to achieve this effect rather than CSS’s hover is that with jQuery it’s a lot easier to have a mouseover effect change the styling of an element other than the one that was hovered upon than it is in CSS. For example, let’s say we want all of the text in the p elements to turn blue when we mouseover that same h1 tag. Here’s what that code would look like:

$("h1").mouseover(function(){
   $("p").css("color", "blue");
})

In the example above, all we had to do to make the mouseover effect apply to an element other than the h1 is replace the “this” keyword with the element we wanted to apply the CSS change to (in this case, “p”). In CSS, achieving this same effect would be more complicated.

Recently Published

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...

article image
»

Check all checkboxes in HTML table using jQuery

HTML tables are a very handy and useful element. They can adapt to ...

article image
»

Changing images in a loop on hover using jQuery

Why use this Function? Changing images in a loop on mouse over is a ...