Problems with jQuery.not () and draggable ui

Well, when something is being dragged, it is assigned the .ui-draggable class and when something is disconnected from the dragging .ui-draggable-disabled

I want to select only draggable objects.

I use the following selector, but it does not work. My disabled draggable items still do something with hovering. Any ideas why?

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

thank

+3
source share
1 answer

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 check for a disabled class in the mouseover / mouseout functions hover:

$(".ui-draggable").hover(function() {
    if(!$(this).hasClass("ui-draggable-disabled")) {
        // do stuff
    }
}, function() {
    if(!$(this).hasClass("ui-draggable-disabled")) {
        // do stuff
    }   
});
+4
source

Source: https://habr.com/ru/post/1743344/


All Articles