If I have CSS p:hover {background-color:yellow}
like this... How to do EXACTLY THE SAME THING with jQuery? No, no a complex set of function calls and property dections, but how to say to jQuery to REUSE this universal browser build-in functionality?
Note after "FAST ATTACK" closing question: se @SamuelLiew's solution operating with 1 line jQuery code, at http://jsfiddle.net/uJXLG/1/
NOTES
This question is about REUSE (of browser build-in functionality), and the sample codes are only illustrations.
Why I need jQuery (instead "pure CSS")?
The use of "pure CSS" not permit to apply logic. Examples: 1) a event that activate and deactivate the CSS houver; 2) a complex selector logic.
Reinforce
Plase, somethig simple as
$('p:hover').css('color','red');
(that NOT RUNS)...
Not say to me to use
$('a').hover(function(){
$(this).css('color', 'red');
},function(){
...
}
);
that is very complex.
EDITED after @nevermind (see user's answer):
the code below is more complex (!!) than a single .addClass
command, as sugested by @SamuelLiew. It is because SamuelLiew's code REUSED the browser's renderization behaviour.
var old_background; // to memorize original background
$.fn.hover_it = function(overcolor) { // TOO COMPLEX CODE AND OVERHEAD FOR DOM!!
$(this).hover(function(){
old_background = $(this).css("background-color");
$(this).css("background-color",overcolor);
},function(){
$(this).css("background-color",old_background);
});
}
$(document).ready(function() {
$('p').hover_it('red');
});