On click apply toggle functions to parent only

Viewed 30

Im trying to toggle a disable/enable function for draggable elements, and I'm trying to apply this only to the parent element of the clicked element where the parent element has class .draggable. It works for the toggled class, but how to I pass (this) to the functions as well?

jQuery("a.check").click(function() {
        jQuery(this).toggleClass("active");
        jQuery(this).hasClass("active") ? disableDrag() : enableDrag();
});

function disableDrag(){
  jQuery(".draggable").draggable("disable");
}
function enableDrag(){
 jQuery(".draggable").draggable("enable");
}

Edit - working solution:

jQuery("a.check").click(function() {
        jQuery(this).toggleClass("active");
        jQuery(this).hasClass("active") ? disableDrag(this) : enableDrag(this);
});

function disableDrag(obj){
  jQuery(obj).closest('.draggable').draggable("disable")
}
function enableDrag(obj){
jQuery(obj).closest('.draggable').draggable("enable")
}
0 Answers
Related