Is there any way to add hover on all elements in html (div,p,span,a…) I’m trying like this:
$("*").hover(
function () {
$(this).addClass('hover'); ;
},
function () {
$(this).removeClass('hover');
}
);
and CSS
#hover {
background-color:#CC0000;
}
but somewhere there is an error???
You should be using a
.rather than a#to denote a class selector.Also, note that using
*as a jQuery selector will select everything, including the body element etc. I’m not sure from the context of the question whether this is what you’re after or not.Furthermore, it would be easier to just use the CSS pseudo-class
:hoverto apply a style to a hovered element. Here’s a reference for how to use it: http://reference.sitepoint.com/css/pseudoclass-hover