Skip to content

Instantly share code, notes, and snippets.

@YayC
Created April 8, 2013 17:53
Show Gist options
  • Save YayC/5338899 to your computer and use it in GitHub Desktop.
Save YayC/5338899 to your computer and use it in GitHub Desktop.
solution to Grocery List
$(document).ready(function($) {
$('.item').draggable({helper: 'clone'});
$('#grocery_list').droppable({accept: '.item', drop:function(e, ui){
$(this).append(ui.draggable.clone());
$('td#total_cost').text(calcTotal());
}
});
calcTotal = function () {
var total = 0;
var item_price = $('#grocery_list td.item_price');
$.each(item_price, function(i,element){
total += parseFloat($(element).text());
});
return total;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment