Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#10926 closed bug (invalid)

Wrap function doesn't wrap jQuery objects unless added to DOM

Reported by: wassimahmed@… Owned by:
Priority: low Milestone: None
Component: manipulation Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

Description

Hi there,

It seems there is a dependency in wrap function which works correctly only if selector points to existing DOM element and doesn't produce anything if selector is a jQuery object which is not yet added to DOM. jsFiddle share (http://jsfiddle.net/SSujs/) describes my problem better.

I hope team can advice why it so and is there someway around this. Couldn't it just work without element added to DOM?

Thanks

Change History (2)

comment:1 Changed 7 years ago by sindresorhus

Component: unfiledmanipulation
Priority: undecidedlow
Resolution: invalid
Status: newclosed

Not a bug, .wrap()returns the original set. From the docs:

This method returns the original set of elements for chaining purposes.

For what you're trying to do, you'll need to add .parent() like this:
$("<a>").wrap("<li>").parent().appendTo("body");

comment:2 Changed 7 years ago by wassimahmed@…

This is to confirm that given solution works for me. Thanks for the help.

Note: See TracTickets for help on using tickets.