Reputation: 104841
Is there a way to eliminate parent element while keeping current element?
Here's my example:
<div id="parent">
<div id="child">
<span>some text</span>
</div>
</div>
div
{
padding: 20px;
}
#parent
{
background-color: green;
}
#child
{
background-color: red;
}
I'm looking for a way to replace the parent div with child
div. Meaning I take #parent
's parent, and replace its inner html with #child
.
I tried playing with visibility but it still takes up the space or hides entire tree.
Is there a CSS way? Otherwise how should it be done easily with jQuery? (note that in my real scenario it's some level up).
Upvotes: 0
Views: 99
Reputation: 74738
There are two ways of doing with .unwrap();
method and .html();
:
With.unwrap()
(preferred way):
$('#child').unwrap();
With .html();
:
var o = $('#child').html();
$('#parent`).html(o);
Upvotes: 1