简体   繁体   中英

Escaped html characters are being unescaped by jquery .html() in some browsers

This is my code:

console.log($('p').html())

<p><span data-htmlContent="&lt;p&gt;This is not really in ap tag.&lt;/p&gt;">.</span>.</p>

In Chrome and older FireFox the console logs: <span data-htmlcontent="&lt;p&gt;This is not really in ap tag.&lt;/p&gt;">.</span>.

But in IE and newer FireFox it logs: <span data-htmlcontent="<p>This is not really in ap tag.</p>">.</span>.

Problem can be seen here: http://jsfiddle.net/Nzj52/9/

It may have something to do with how each browsers console operates compared to the rendering operation. If you did and alert instead - would your answer change?

Instead of calling console.log($('p').html()); Try calling console.log($('p').text());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM