2.0.0 • Published 6 years ago

jquery-unique-clone v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

jQuery Unique Clone

Like $(element).clone() but will ensure that each ID in the cloned element is unique.

Useage

With given HTML:

<div class="container">
  <label for="foobar">Foo Bar</label>
  <input type="text" id="foobar">
</div>

This JavaScript:

$('.container').uniqueClone();

Will return a jQuery collection representing:

<div class="container">
  <label for="foobar-clone">Foo Bar</label>
  <input type="text" id="foobar-clone">
</div>

Options

This plugin's API mimics the core clone method.

paramtypedefault valuedescription
withDataAndEventsBooleanfalseindicates whether event handlers should be copied along with the elements.
deepWithDataAndEventsBooleanvalue of withDataAndEventsindicates whether event handlers and data for all children of the cloned element should be copied. By default it's value matches the first argument's value, which defaults to false.
suffixString-clonethe string to be appended to the end of the ID or FOR attribute value.

Examples

$(element).uniqueClone();
$(element).uniqueClone(true);
$(element).uniqueClone(true, false, '-in-dialog')

Running Tests

git clone git@github.com:meowsus/jquery-unique-clone.git
cd jquery-unique-clone
npm install
gulp mocha