.delegate equivalent of an existing .live 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:23 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

I have an event handler bound to the hover event using the .live 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