jquery: problem with unbinding mousenter() upon mouseup()

Posted by Haroldo on Stack Overflow See other posts from Stack Overflow or by Haroldo
Published on 2010-04-20T09:22:41Z Indexed on 2010/04/20 9:23 UTC
Read the original article Hit count: 498

Filed under:

I'm building an interface for marking dates on a calendar as being booked. The user 'paints' on the dates they want to mark as booked.

here's how it looks:

alt text

here are the functions:

function load_red_paint(){
    $('td').bind('mousedown', function(){
        $(this).addClass('booked');
        $('td').bind('mouseenter', function(){
            $(this).addClass('booked');
        });
    unbind_brush();
    })  
}

function unbind_brush(){
    $('td').bind('mouseup', function(){
        $('td').unbind('mouseenter');
    });
    $('table').bind('mouseleave', function(){
        $('td').unbind('mouseenter');
    });
}

the problem:

My unbind_brush() function works great except for if the user mouseup's outside of the calendar, i tried to fix this my also unbinding on mouseleave of that calendar with this bit:

$('table').bind('mouseleave', function(){
    $('td').unbind('mouseenter');
});

but with no joy, am i missing something obvious?!!!

© Stack Overflow or respective owner

Related posts about jQuery