Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove p tag using jquery without deleting content

Tags:

html

jquery

My situation is like this

<p><img src="/media/118711/banner.jpg" width="344" height="113" alt="Banner"></p>

I want to delete the p tag using jquery but I do not need to delete content(image). Any one please can help me?

like image 941
None Avatar asked Apr 05 '12 12:04

None


2 Answers

This should do it...

$('p > *').unwrap();

jsFiddle.

like image 127
alex Avatar answered Nov 15 '22 20:11

alex


Selector $('p > *') works only when content of p is another tag. If it contains only text, then this selector doesn't hit it. This works for me:

$("p").each(function() { 
    $(this).replaceWith($(this).html());
}); 
like image 39
juice Avatar answered Nov 15 '22 22:11

juice