Side navigation
#10189 closed bug (invalid)
Opened September 02, 2011 03:21AM UTC
Closed September 02, 2011 03:46AM UTC
Last modified September 02, 2011 03:20PM UTC
.wrap() fails to set the wrapper's parent
Reported by: | justin.stayton@gmail.com | 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.
Attachments (0)
Change History (4)
Changed September 02, 2011 03:46AM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
Changed September 02, 2011 02:13PM UTC by comment:2
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.
Changed September 02, 2011 03:13PM UTC by comment:3
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.
Changed September 02, 2011 03:20PM UTC by comment:4
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.