Reputation: 167
How would you say :not(this) in the case of this code:
$(".draghandle").droppable({
accept: ".draghandle:not(this)"
drop: function ( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
You'll see the selector right next to the accept option is probably invalid, though I haven't checked to see, I was wondering if you might have a solution as to validating it? I have yet to find one, but don't be discouraged if you have a solution that changes another part of the code as well, I just need a fix. Here's a similar question I'm trying to expand on: jQuery: exclude $(this) from selector And here's a link to the main code for this that I'm using as reference: http://jqueryui.com/demos/droppable/#accepted-elements
Upvotes: 0
Views: 2219
Reputation: 78560
You can pass a jQuery list as the accept argument instead of just a selector. In the following demo, I make all .ui-widget-content
elements droppable except the #draggable
one. (reversing the original jQuery UI site demo). the parameter I passed to accept
was $(".ui-widget-content").not("#draggable")
.
http://jsfiddle.net/5TZ7b/
http://jsfiddle.net/5TZ7b/show
$(function() {
$( "#draggable, #draggable-nonvalid" ).draggable();
$( "#droppable" ).droppable({
accept: $(".ui-widget-content").not("#draggable"),
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
});
You can use the following as the parameter passed to accept
.
$(".draghandle").not(this)
Upvotes: 3