#10189 closed bug (invalid)
.wrap() fails to set the wrapper's parent
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Everything explained in this example: http://jsfiddle.net/tvusW/
Using Google Chrome on OS X Lion with jQuery 1.6.2.
Change History (4)
comment:1 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 11 years ago by
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 11 years ago by
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 11 years ago by
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!
If you look at the document that results after the wrapping, the method did its job; the
input
is wrapped in adiv
.The docs say:
Clearly, if there were two
input
s in the selection the SAMEdiv
could not be wrapped around bothinput
s, right? View thewrappingElement
as a template for the content that will be wrapped.