Jquery – Perform callback after append
jQuery’s .each() takes a callback function and applies it to each element in the jQuery object. Imagine something like this: $(‘a.ui-icon-cart’).click(function(){ $(this).closest(‘li’).clone().appendTo(‘#cart ul’).each(function() { $(this).find(‘h5’).remove(); $(this).find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $(this).find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); }); You could also just store the result and work on it instead: $(‘a.ui-icon-cart’).click(function(){ var $new = $(this).closest(‘li’).clone().appendTo(‘#cart ul’) $new.find(‘h5’).remove(); $new.find(‘img’).css({‘height’:’40px’, ‘width’:’40px’}); $new.find(‘li’).css({‘height’:’60px’, ‘width’:’40px’}); }); … Read more