Skip to main content

Bug Tracker

Side navigation

#11153 closed bug (fixed)

Opened January 10, 2012 06:52PM UTC

Closed March 30, 2012 09:10PM UTC

Last modified March 18, 2014 06:09PM UTC

jQuery 1.7 Strips Carriage Returns in IE 8

Reported by: drlongghost@yahoo.com Owned by:
Priority: low Milestone: 1.8
Component: attributes Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

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.

Attachments (0)
Change History (6)

Changed January 31, 2012 12:50PM UTC by sindresorhus comment:1

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/

Changed January 31, 2012 01:59PM UTC by sindresorhus comment:2

#11262 is a duplicate of this ticket.

Changed March 08, 2012 02:34PM UTC by anonymous comment:3

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?

Changed March 10, 2012 01:31PM UTC by dmethvin comment:4

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.

Changed March 30, 2012 09:10PM UTC by timmywil comment:5

resolution: → fixed
status: openclosed

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

Changeset: a29d482894a844724f4386f2fed0edf9cf70c069

Changed March 18, 2014 06:09PM UTC by Hartmut comment:6

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};

}}}

with:

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,

Hartmut