Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#11153 closed bug (fixed)

jQuery 1.7 Strips Carriage Returns in IE 8

Reported by: drlongghost@… Owned by:
Priority: low Milestone: 1.8
Component: attributes Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:


In versions of jQuery prior to 1.7, new nodes which are inserted preserve all carriage returns in IE 8. This is now broken in 1.7.

Test Case page: http://jsfiddle.net/27DGw/3/

In the above test case, in all browsers except IE 8, the value which is alerted is "One\nTwo". In IE 8, the alerted value is "OneTwo".

Note that when you change the jquery library to a version < 1.7, IE 8 returns the expected, correct value.

The workaround I'm forced to adopt for the app I'm working on is to use non-jquery, native javascript methods to append items to the DOM in cases where the carriage returns are significant.

Change History (6)

comment:1 Changed 11 years ago by sindresorhus

Component: unfiledmisc
Priority: undecidedlow
Status: newopen

From the .text() docs:

Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.

An performance refactor to the getText sizzle method, which is used by .text, was landed in 1.7, which means it now uses textContent/innerText to get the text of elements. Previously it went through all the elements nodeValue property, which was less performant. getText strips carriage returns in IE, don't know exactly why, probably for consistency?

Anyhow, you could use innerText directly, which will convert <br /> to newline automatically: http://jsfiddle.net/mofle/GQXJF/

comment:2 Changed 11 years ago by sindresorhus

#11262 is a duplicate of this ticket.

comment:3 Changed 11 years ago by anonymous

FWIW, I do feel this is a legitimate bug that should be addressed. While it may seem incongruous, the inconsistent behavior complicates cross-browser implementation of contenteditable interfaces, among other things.

Could the performance enhancement you mentioned use a conditional so it defaults to the slower, more correct method for IE <= 8?

comment:4 Changed 11 years ago by dmethvin

Component: miscattributes
Milestone: None1.8

Yes, this was due to the changes to Sizzle.getText(), probably the only way to fix it is to go back to the old way (at minimum for oldIE). Let's review and decide for 1.8.

comment:5 Changed 11 years ago by Timmy Willison

Resolution: fixed
Status: openclosed

Update Sizzle and add test for sizzle getText fix. Removes usage of innerText. Fixes #11153.

Changeset: a29d482894a844724f4386f2fed0edf9cf70c069

comment:6 Changed 9 years ago by Hartmut

Hi, recently recognised massive performance problems with the usage of "textContent" instead of "innerText" in IE10 and much more in IE11.

Performance measurement with IE 11.0.9600.16521 on some real productive test-scenario:
With "textContent" used: 3618ms
With "innerText" used: 246ms

Page has been really slow and laggy in IE10 + IE11 while it's fluent and fast in e.g. FF / Chrome...

Here some fix I use for jQuery v1.8.3:
I have replaced:

b0=cQ.getText=function(da){var c9,c7="",c8=0,e=da.nodeType;if(e){if(e===1||e===9||e===11){if(typeof da.textContent==="string"){return da.textContent}else{for(da=da.firstChild;da;da=da.nextSibling){c7+=b0(da)}}}else{if(e===3||e===4){return da.nodeValue}}}else{for(;(c9=da[c8]);c8++){c7+=b0(c9)}}return c7};


b0=cQ.getText=function(da){var c9,c7="",c8=0,e=da.nodeType;if(e){if(e===1||e===9||e===11){var txtC=da.textContent;if(typeof txtC==="string"){return txtC}else{for(da=da.firstChild;da;da=da.nextSibling){c7+=b0(da)}}}else{if(e===3||e===4){return da.nodeValue}}}else{for(;(c9=da[c8]);c8++){c7+=b0(c9)}}return c7};

Maybe this bugfix should be checked!

Kind Regards,

Note: See TracTickets for help on using tickets.