Reputation: 374
I have a question regarding remove the html tags from string apart from the image tag. Let's say we have a string like :
<p>MA2: Allow time for editing and other types of question revisions.<span class="AM"> <img src="img" title="{(1 if x>=0),(0 if x<0):}"style="vertical-align: middle;"> </span> <span class="AM"> </span> </p>
In this we only need to remove the <p>
and <span>
like the html tags. But we need the image tag.
Expected Result :
MA2: Allow time for editing and other types of question revisions.<img src="img" title="{(1 if x>=0),(0 if x<0):}" style="vertical-align: middle;">
Thanks in advance.
Upvotes: 0
Views: 257
Reputation: 108
$('span').contents().unwrap();
$('p').contents().unwrap();
For all elements except images:
$('*').not('img').contents().unwrap();
More here:
http://api.jquery.com/contents/
Upvotes: 2