Web development by Gabriele Romanato

Post navigation

jQuery: the clone() method

jQuery provides, among other DOM methods, a simple method to clone an element with all its children. This method is called clone() and accepts as its optional value a Boolean flag that specifies whether event handlers must be cloned along with the elements they're attached to. This flag defaults to false. Bear in mind, however, that even attributes are cloned, so you should use this method carefully. For example, given the following DOM structure: