There is such a problem.

And the problem is this: we have <input> , we need to wrap it in a <div> , then again in <div> and again in <div> . Then the penultimate <div> cloned and pasted into the last <div> .

In essence, it should come out:

 <div class='wrapper'> <div class='info'> <div> <input> </div> </div> <div class='info'> <div> <input> </div> </div> </div> 

In fact, nothing complicated, but this way does not work:

 var $wrapper = $("<div>").addClass("wrapper"); var $wrapper_two = $("<div class='info'><div></div></div>").appendTo($wrapper); $("input").wrap($wrapper); $wrapper_two.clone().appendTo($wrapper); 

And the width can not find out:

 console.log($wrapper.width()); // => 0 

To test: http://jsfiddle.net/1w08fhpv/6/

  • Maybe var $ wrapper = $ ("<div> </ div>"). AddClass ("wrapper"); - OlegUP
  • and what generally comes out? - OlegUP
  • @OlegUP take a look at the example, I indicated the link: jsfiddle.net/1w08fhpv/6 - lampa
  • I do not understand what the problem is, as if the item is being cached. While solved a problem, we receive the parent from input. - lampa
  • No one knows what the problem is? - lampa

1 answer 1

When wrap, the object is cloned.

it's all the fault of this line

wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );

what exactly made the developer do cloning here I did not find. here is the commit in which it occurs for the first time

8a4a1edf Initial import

here, just in case, a demo with a parent without reference to the wrapper2 structure http://jsfiddle.net/1w08fhpv/7/

dirty patched wrap and wrap All

and finally, the "normal" solution

  • I decided this: I wrapped everything in .wrapper and through parents () I just got this .wapper again. - lampa