Ayaz Ali Shah
Ayaz Ali Shah

Reputation: 3541

How to remove child element without losing the content using jquery?

I'm trying to remove the <p> tag inside the <h3> without losing the content.

<h3 class="blog-heading">
    <p>This is content</p>
</h3>

I tried with unwrap(), remove() and empty() function but these functions are removing my data as well.

$('.blog-heading').find('p').remove();

Can any one guide me is this possible in jquery and how can i fix this. I will appreciate. Thank You.

Upvotes: 1

Views: 98

Answers (2)

A. Wolff
A. Wolff

Reputation: 74420

You want to unwrap p content:

$('.blog-heading p').contents().unwrap();

Upvotes: 3

shu
shu

Reputation: 1956

try the following

$('.blog-heading').text($('.blog-heading').find('p').text())

Upvotes: 0

Related Questions