JQuery adding class to cloned element
问题 This is my script: $('.addprop').click(function() { $('#clone').clone().insertAfter('.addprop'); }) I need to add a class to the new element that is being created. Is it possible? 回答1: Yes, it is: $('.addprop').click(function() { $('#clone').clone().addClass('newClass').insertAfter('.addprop'); }) Although you're cloning an element based on its id , $('#clone') , so note that there will be two elements sharing the same id , which makes the result invalid HTML, so I'd suggest: $('.addprop')