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!
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.
fn. hover() is deprecated #66.
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);
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.
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');
});
});
JQuery
$(".box a").hover(function(){
$(this).parent().css('background-color', '#fff200');
}, function() {
$(this).parent().css('background-color', '#ffffff');
});
See fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With