JQuery - can I dynamically change the parent element? And a new element and make it a parent choice?

I have a div #someDiv, can I create a new element and make #someDiv its child? Basically, I want to wrap a new element next to C # someDiv. How to do it?

$("#someDiv").appendTo($("<div id='newParent'></div>")); 
// The intent is to move #someDiv into the new container
// The new container may or may not be in the same 
// position in the DOM as #someDiv

Thanks for any tips!

Cheers, ~ ck in San Diego

+3
source share
5 answers
$("#something").wrap("<div id='newParent'></div>");
+2
source
$("#someDiv").wrap("<div id='newParent'></div>");
+1
source

. anyting jquery. jQuery.wrap

0

, someDiv ...

$('#someDiv').wrap('<div>')

, . .

0

divarent , wrap.

$('somediv').wrap("<div id='newparent'></div>");

, , , .

0

Source: https://habr.com/ru/post/1727837/


All Articles