Ticket #10189 (closed bug: invalid)
.wrap() fails to set the wrapper's parent
| Reported by: | justin.stayton@… | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.6.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Everything explained in this example: http://jsfiddle.net/tvusW/
Using Google Chrome on OS X Lion with jQuery 1.6.2.
Change History
comment:1 Changed 21 months ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
comment:2 Changed 21 months ago by justin.stayton@…
True, the input is being wrapped correctly by the div. The action of wrapping works as expected. However, the issue I'm seeing is that the div's parent isn't being correctly set. It should be the form, but it's saying it has no parent, which is obviously incorrect. My example shows two things: 1) it shows that .wrap() doesn't set the div's parent, and 2) then it resets the example and shows that appending the input to the div (accomplishing the same thing as .wrap(), just in a different way) does correctly set the div's parent.
Sorry if my example wasn't completely clear, but I still believe this is a legitimate bug.
comment:3 Changed 21 months ago by dmethvin
The code asks for .wrap() to wrap the input in a div. It did that, making a *copy* of the div from $wrapper and wrapping the input with the copy. The method doesn't say the wrapping elements are the original ones you specified, only that the same structure is used. And clearly for a jQuery object with more than 1 element, it cannot use the same elements that are passed in, it has to make copies.
If you explicitly insert $wrapper into the DOM yourself, the outcome is different since you've put *that* element in the DOM and not a copy. If that's the desired behavior, use that code instead.
comment:4 Changed 21 months ago by justin.stayton@…
Ah, that makes sense. Sorry, I didn't understand that it makes a copy. I see now that the last example in the documentation for .wrap() ( http://api.jquery.com/wrap/) specifies that a copy is made. Thanks for your help!
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

If you look at the document that results after the wrapping, the method did its job; the input is wrapped in a div.
The docs say:
Clearly, if there were two inputs in the selection the SAME div could not be wrapped around both inputs, right? View the wrappingElement as a template for the content that will be wrapped.