Can I cut (completely, with all styles and attributes) an element from a location and paste it in another location (like body
) with jQuery?
Also, I want to place a string (or tag) in the old location, because I want to change its place to old location at the end of the script.
Can I? How?
appendTo() will automatically move the matched elements from their current location to the specified container, which seems to be what you want.
You can use after() to insert new content before moving the element:
$("#yourElement").after("<p>Element was there</p>").appendTo("body");
.detach()
is more appropriate for this task, as @lvan suggested.
jQuery(jQuery("#yourElement").detach()).appendTo("body");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With