usertest
usertest

Reputation: 27648

Remove some tags in jquery

I would like to use jquery to remove some tags inside mainclass, so that this -

<div class='mainclass'>
<div class='inclass'>
<a href='#'>Some text</a>
</div>
</div>

Becomes this -

<div class='mainclass'>
Some text
</div>

Thanks in advance.

Upvotes: 0

Views: 185

Answers (3)

Shiki
Shiki

Reputation: 16808

Store the text you want to preserve, remove the elements and set the text to the main div.

var sometext = $('.mainclass > .inclass > a').text();
$('.mainclass').remove('.inclass').text(sometext);

Upvotes: 0

x1a4
x1a4

Reputation: 19496

$('.mainclass').text($('.inclass').text());

Upvotes: 3

ryanulit
ryanulit

Reputation: 5001

$('.mainclass').html($('.inclass > a').text());

Upvotes: 0

Related Questions