Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10189 closed bug (invalid)

.wrap() fails to set the wrapper's parent

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


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 dmethvin

Resolution: invalid
Status: newclosed

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:

The structure will be wrapped around each of the elements in the set of matched elements.

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.

comment:2 Changed 11 years ago by [email protected]

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 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 11 years ago by [email protected]

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!

Note: See TracTickets for help on using tickets.