Jquery: Strip all specifc HTML tags from string
<p>I have a variable that contains a string of text and html tags, such as:</p>

<pre><code>var temp = "&lt;div&gt;Some text&lt;/div&gt;&lt;p&gt;More text&lt;span&gt;here&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Even more&lt;/p&gt;";
</code></pre>

<p>I would like to remove all tags of a certain type. Let's say all <code>p</code> and <code>span</code> tags for example.</p>

<p>This is the best I can come up with:</p>

<pre><code>var temp = "&lt;div&gt;Some text&lt;/div&gt;&lt;p&gt;More text&lt;span&gt;here&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Even more&lt;/p&gt;";
var $temp = $(temp);
$("p", $temp).replaceWith("foo");
alert($temp.html());  //returns "Some text"
</code></pre>

<p>There are a number of other similar questions on SO, but none of the responses have helped me with this issue. The closest response I could find is this answer by Nick Craver: <a href="http://stackoverflow.com/questions/3797385/strip-span-tags-from-string-with-jquery">strip span tags from string with jquery</a>. </p>

<p>Any help will be appreciated.</p>
