.delegate equivalent of an existing .hover method in jQuery 1.4.2

Posted by kim3er on Stack Overflow See other posts from Stack Overflow or by kim3er
Published on 2010-04-07T11:14:18Z Indexed on 2010/04/07 11:53 UTC
Read the original article Hit count: 468

Filed under:
|
|
|

I have an event handler bound to the hover event using the .hover method, which is below:

$(".nav li").hover(function () {
    $(this).addClass("hover");
}, function () {
    $(this).removeClass("hover");
});

It is important to note, that I require both functions within the handler to ensure synchronisation. Is it possible to rewrite the function using .delegate, as the following does not work?

$(".nav").delegate("li", "hover", function () {
    $(this).addClass("hover");
}, function () {
    $(this).removeClass("hover");
});

Rich

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about event-handling