Al.G.
Al.G.

Reputation: 4406

Manipulating jQuery object without changing the html element

I have a variable with a jQuery object, for example:

var div = $('#div_element');

How can I manipulate ONLY the div variable, without changing the #div_element itself?


I want to do some edits on the div variable and to pass it as an argument to a plugin, like this:

var el = $('#div');
el.find(':first').remove();
$().popup(el); //I wrote this plugin myself

Actually I want to display popup containing the #div element (with removed the first "child"), but don't want to change the #div element itself.

Upvotes: 1

Views: 592

Answers (2)

Anoop Joshi P
Anoop Joshi P

Reputation: 25537

You can use like

$().popup($("#div :not(:first-child)"));

Upvotes: 1

user229044
user229044

Reputation: 239521

Use clone to create a copy of the element.

var el = $('#div').clone();

Upvotes: 6

Related Questions