Thanks for looking at this question in advance.
I’m using jQuery drag and drop for a project I’m doing at university and I’m looking to count each drop and change the class that is added on each drop.
Here is the jQuery:
$('#droppableChoking').droppable({
drop: function (event, ui) {
//reuse jQuery object
var $this = $(this);
//get object type
var droppedObject = ui.draggable.data('object');
//css reset
$this.removeClass();
$this.addClass("grape" + droppedObject);
}
//play drop sound
audioClap.play();
}
});
I’ve tried doing a loop and add the value of the count to the class to change it each time but I’m doing something wrong!
http://api.jquery.com/removeClass/
removeClassrequires One or more space-separated classes to be removed from the class attribute of each matched element.So with that in mind, your call to removeClass isn’t likely removing anything. If you want to clear out the class, then do
$this.attr('class', '')As for a counter, here is my updated JS: