Skip to main content

Bug Tracker

Side navigation

#11046 closed bug (wontfix)

Opened December 16, 2011 07:58PM UTC

Closed December 16, 2011 08:06PM UTC

Last modified December 16, 2011 10:29PM UTC

.text() property strips whitespace on IE 8

Reported by: ido@redit.us Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

The following snippet:

$('<h1><div>sub</div> title</h1>').text();

Correctly returns: "sub title" on Chrome, FireFox and IE9.

But on IE 8 it returns: "subtitle"

Attachments (0)
Change History (3)

Changed December 16, 2011 08:01PM UTC by ido@redit.us comment:1

jsFiddle example:

http://jsfiddle.net/Qebq5/

Changed December 16, 2011 08:06PM UTC by rwaldron comment:2

resolution: → wontfix
status: newclosed

http://api.jquery.com/text/

Unlike the .html() method, .text() can be used in both XML and HTML documents. The result of the .text() method is a string containing the combined text of all matched elements. (Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space.) Consider the following HTML

Changed December 16, 2011 10:29PM UTC by dmethvin comment:3

Just so you know it isn't jQuery doing the mangling:

http://jsfiddle.net/zXAph/

IE8 and lower in particular likes to do strange things with whitespace.