Delete tag using jquery without deleting content

My position is like this

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

I want to remove the p tag using jquery, but I do not need to delete the content (image). Can anybody help me?

+7
source share
2 answers

That should do it ...

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

jsFiddle .

+13
source

The $('p > *') selector only works when the contents of p is another tag. If it contains only text, this selector did not hit it. This works for me:

 $("p").each(function() { $(this).replaceWith($(this).html()); }); 
+4
source

All Articles