5

This is my code:

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

<p><span data-htmlContent="&lt;p&gt;This is not really in a p 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 a p tag.&lt;/p&gt;">.</span>.

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

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

7
  • 1
    I'm getting the same result in FF24 and ie10
    – megawac
    Nov 20, 2013 at 16:39
  • very interesting bug... my first guess is a problem with jQuery's html() selector, but let me play with it and see what I come up with. Nov 20, 2013 at 16:40
  • @megawac, how disheartening. It was working in an old version of FF but when I updated, it broke just like you said. I'll edit question. Nov 20, 2013 at 16:50
  • 2
    The problem isn't regex related at all : the problem is that the &lt; and &gt; are unescaped in the HTML given by the html function (the oldHtml string) even while they're in an attribute. This question should be fixed to remove all references to regexes and include the relevant parts. Nov 20, 2013 at 16:51
  • Note also that this isn't a jQuery bug, it rather looks like a bug in innerHTML accessor. Nov 20, 2013 at 16:57

1 Answer 1

0

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());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.