(ui1.5) drag and drop filling a table -> help me plz!
hey all,
im using jquery1.2.4a, and jquery.ui1.5b4 (ui.draggable and ui.droppable)
im working on a way to drag and drop items from a list into an existing table and so far it works perfectly but my code is all over the place... i'd really appreciate it if someone could help me optimize it a bit... thanls!
-
$(document).ready(function(){
$(".drag").draggable({helper: 'clone'});
$(".drop").droppable({
accept: ".drag",
activeClass: 'droppable-active',
hoverClass: 'droppable-hover',
drop: function(ev, ui) {
var tr = $(document.createElement('tr'));
var td = $(document.createElement('td'));
var img = $(document.createElement('img')).attr({
src: $(ui.draggable).attr('src'),
title: $(ui.draggable).attr('title')
});
$(td).append(img);
$(tr).append(td);
td = $(document.createElement('td'));
var title = $(document.createElement('div')).text($(ui.draggable).attr('title'));
$(td).append(title);
$(tr).append(td);
td = $(document.createElement('td'));
var name= $(document.createElement('div')).text($(ui.draggable).attr('name'));
$(td).append(name);
$(tr).append(td);
$('#mytable').append(tr);
}
});
});
basically, i'm wondering whether there's a more elegant way of appending the information onto my table without creating tons of variables and appending them one by one like i'm doing right now... thanks!
