Try adding that code into the "drop" event. Here is a demo.
HTML
<div class="draggable ui-widget-content correct"><p>1</p></div>
<div class="draggable ui-widget-content"><p>2</p></div>
<div class="draggable ui-widget-content"><p>3</p></div>
<div class="draggable ui-widget-content"><p>4</p></div>
<br style="clear: both">
<div id="droppable" class="ui-widget-header">
<p>Drop me here</p>
</div>
Script
$(function() {
$(".draggable").draggable({ revert: true });
$("#droppable").droppable({
activeClass: 'ui-state-hover',
hoverClass: 'ui-state-active',
// uncomment the line below to only accept the .correct class..
// Note: the "drop" function will not be called if not ".correct"
// accept : '.correct',
drop: function(event, ui) {
// alternative method:
// if (ui.draggable.find('p').text() == "1") {
if (ui.draggable.is('.correct')) {
$(this).addClass('ui-state-highlight').find('p').html('You got it!');
// cloning and appending prevents the revert animation from still occurring
ui.draggable.clone(true).css('position', 'inherit').appendTo($(this));
ui.draggable.remove();
} else {
$('#droppable > p').html('Not that one!')
setTimeout(function(){ $('#droppable > p').html('Drop here'); }, 1000);
}
}
});
});
As you can see in the script, you can either look for the .correct
class or the text inside (commented out line)