Reputation: 1022
I'm wrapping some elements using the jQuery wrapInner function. Like this.
$( "#container" ).wrapInner( "<div></div>" );
But I want to know the best way make a reference to this newly created div. I was hoping I could just do
var featuresWrap = $( "#container" ).wrapInner( "<div></div>" );
But this just creates a reference to "#container". So is this best way just to do the following?
$( "#container" ).wrapInner( "<div></div>" );
var featuresWrap = $( "#container div" );
Thanks
Upvotes: 0
Views: 240
Reputation: 24788
Because wrapInner
causes the element to have one immediate child, you can simply do:
var featuresWrap = $("#container").wrapInner("<div>").children();
to get the jQuery object associated with the created div.
In order to get the associated HTMLElement
, simply do:
var htmlElement = featuresWrap.get(0);
Upvotes: 4