Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery un-hover

Tags:

jquery

I have this script to cause a background color on a paragraph on hover of link within the paragraph. What I don't know how to do is cause it to return to the original background color once I "un-hover".

$(function(){
    $(".box a").hover(function(){
    $(this).parent().css('background-color', '#fff200');
    });
});

Thanks!

like image 527
user1754427 Avatar asked Mar 07 '13 16:03

user1754427


People also ask

What is hover() method in jQuery?

The hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.

Is hover deprecated in jQuery?

fn. hover() is deprecated #66.

How to set hover in jQuery?

The hover() is an inbuilt method in jQuery which is used to specify two functions to start when mouse pointer move over the selected element. Syntax: $(selector). hover(Function_in, Function_out);

How do you know if an element is hovered?

You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery. The jQuery code in the following example will display a hint message on the web page when you place or remove the mouse pointer over the DIV element's box.


2 Answers

The function below works as onmouseover and onmouseout

$(function () {
    $(".box a").hover(function () {
        $(this).parent().css('background-color', '#fff200');
    }, function () {
        // change to any color that was previously used.
        $(this).parent().css('background-color', '#fff200');
    });
});
like image 200
meewog Avatar answered Sep 30 '22 18:09

meewog


JQuery

$(".box a").hover(function(){
    $(this).parent().css('background-color', '#fff200');
 }, function() {
     $(this).parent().css('background-color', '#ffffff');
 });

See fiddle.

like image 24
soyuka Avatar answered Sep 30 '22 19:09

soyuka