Whenever a user presses a div button I want to register a droppable. I’m setting a the closure
add.droppable({}) to the var toDrop and then invoking methods on toDrop as below, is this a bad practice ?
For example instead of toDrop.addClass("newColors"); should I be using something like
this.addClass("newColors")
Here is the complete snippet :
$("#myDiv").on('click' , '.colors' , function() {
var add = $(this).parent();
var toDrop = add.droppable({
drop: function(event, ui) {
toDrop.addClass("newColors");
toDrop.attr("portletName", parameter);
}
});
});
Unless you want to use that variable
tpDropother than in the drop handler it is advisable to usethiskeyword instead of a creating a closure which represents the droppable element.So you should be using
$(this).addClass("newColors");You can make use of jQuery chaining feature.
$(this).addClass("newColors").attr("portletName", parameter);