开发者

Problems with jQuery .not() and the draggable ui

开发者 https://www.devze.com 2022-12-28 09:24 出处:网络
Okay, when something is draggable, it is given the class .ui-draggable And when something is disabled from being draggable .ui-draggable-disabled

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 selec开发者_开发知识库tor, 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


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
    }   
});
0

精彩评论

暂无评论...
验证码 换一张
取 消