Chris McClellan
Chris McClellan

Reputation: 1105

.clone() remains unchanged?

So lets do this when the DOM is ready:

var parent_copy;  // global scope in this context

function preDeviceSetup() {  // only fired once - should be enough to set parent_copy
  parent_copy = $('.parent').clone(true);  // passes clone to var parent_copy;
}

I want to do this more than once after some event:

function listWrap(count) {
  $(parent_copy).replaceAll('.parent');
  //...
}

Is parent_copy going to still hold the original clone? Throughout the script changes are made within the .parent element and I want it to be over written possibly more than once with the original. Sorry if this doesn't make much sense, just going on 3 hours of sleep (which isn't enough).

Upvotes: 0

Views: 127

Answers (1)

Jeff Meatball Yang
Jeff Meatball Yang

Reputation: 39027

You don't need the $() around $(parent_copy) since it's already a jQuery-wrapped object via the clone() call. Also, parent_copy will be moved into the document when being used as the source of the replaceAll, so you will need to call clone again, to avoid losing the original clone:

function list_wrap(count) {
  parent_copy.clone(true).replaceAll('.parent');
  //...
}

Upvotes: 2

Related Questions