javascript - Why does using replace to unescape html tags strips out all other html tags as well? -


i need convert &lt; , &gt; in table < , >. function i'm using works well.

<div class="schedule">     <table>       <tbody>         <tr>           <td>lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua.&lt;br /&gt;             <em>ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</em>&lt;br /&gt;duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</td>         </tr>       </tbody>     </table> </div> 

and

$('.table-container td').each(function(){   var $this = $(this);   var t = $this.text();   $this.html(t.replace('&lt','<').replace('&gt', '>')); }); 

however, function removes <em> tags don't need unescaping. know why?

https://jsfiddle.net/et1crlug/

because used .text() html content.

use .html() instead:

var t = $this.html(); 

https://jsfiddle.net/et1crlug/1/


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -