Search code examples
javascriptjqueryclone

Unique NAME to clone() elements


How do I give an unique NAME or other ATTR to a element that is cloned?

Thank you in advance.


Solution

  • A hack-ish way to do this would be to use a global counter and keep incrementing it by One before adding the value to the name of the cloned element.

    ex.

    var count =1;
    func some_func() {
         var cloneElement = $(form).clone();
         cloneElement.attr('name', cloneElement.attr('name') + count++);
    }