views:

33

answers:

1

Okay, when something is draggable, it is given the class .ui-draggable And when something is disabled from being draggable .ui-draggable-disabled

I want to select only items that are draggable.

I'm using the following selector, but it doesn't seem to work. My disabled draggable items are still doing something on hover. Any ideas why?

$('.ui-draggable').not('.ui-draggable-disabled').hover(function() {
// rest of code

Thanks

+4  A: 

Try:

// selector means "doesn't have", ':not(:has(selector))'
$(".ui-draggable:not(:has(.ui-draggable-disabled))").hover(function() { ...

or:

$('.ui-draggable').not(':has(.ui-draggable-disabled)').hover(function() {

or test for the presence of the disabled class within the hover mouseover/mouseout functions:

$(".ui-draggable").hover(function() {
    if(!$(this).hasClass("ui-draggable-disabled")) {
        // do stuff
    }
}, function() {
    if(!$(this).hasClass("ui-draggable-disabled")) {
        // do stuff
    }   
});
karim79
Thanks. I thought that would do the trick. Alas it doesn't. Weird.
Chris
@Chris - None of the above methods work? Oh dear.
karim79
No. It's a bit strange. I've tried removing the class too (in the same function that disables the draggable function), but jQuery still seems think the class still exists, and consequently does stuff on hover.
Chris
I tell a lie. The if statement works. There was an erroneous period in your code though.Thanks for your help. Really appreciate it.
Chris