$('body').on('click', 'td.new-green-fruit', function() { data2 = this.innerHTML; k2 = Object.keys(obj).find(k => obj[k].indexOf(data2) >= 0) index2 = obj[k2].indexOf(data2); obj[k2].splice(index2, 1); obj2[key3].push(data2); $(this).parent().detach(); var element2 = $(this).detach(); $('#fruityid > tbody').append('<tr><td>' + element2.html() + '</td></tr>'); });