Skip to main content

Bug Tracker

Side navigation

#7923 closed bug (duplicate)

Opened January 07, 2011 11:24PM UTC

Closed January 08, 2011 01:41AM UTC

Last modified January 08, 2011 02:05AM UTC

Documentation bug: .text() does not always return CDATA

Reported by: walter@infbio.com Owned by:
Priority: undecided Milestone: 1.next
Component: manipulation Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

http://bugs.jquery.com/ticket/6827 was closed wontfix ("use .html()").

However, the documentation (http://api.jquery.com/text/) says .text() returns CDATA, which it doesn't -- apparently by design.

Either 6827 should be fixed, or the documentation should reflect the SCRIPT element restriction.

Attachments (0)
Change History (4)

Changed January 07, 2011 11:25PM UTC by walter@infbio.com comment:1

Here's a jsFiddle just for completeness. No output on IE8.

http://jsfiddle.net/xMDn6/

Changed January 08, 2011 01:41AM UTC by jitter comment:2

component: unfiledmanipulation
resolution: → duplicate
status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report.

As the (I admit that it's rather scarce) closing text for #6827 states, you should use .html() instead of .text() to retrieve the content of script tag. This test case works for me in IE.

The documentation on .text() is correct in stating that it returns the value of CDATA nodes. But in this case there is no CDATA node just a script tag which is a Element node and this Element node (in all browser but IE) has a single child node which is a text node.

Changed January 08, 2011 01:41AM UTC by jitter comment:3

Duplicate of #6827.

Changed January 08, 2011 02:05AM UTC by anonymous comment:4

And thanks for your quick response!

The "use

.html()
" text is so scarce that you didn't see I had it in the original description. :)

The

.text()
method is documented to "get the combined text contents of each element". It returns
""
. If the documentation is correct, that must mean the
script
tag and its descendants are considered to have no text contents at all, which is unexpected (at least to me). That it differs across browsers is even more unexpected.

I filed a documentation bug because I didn't expect to have to go find a closed bug report to discover that this inconsistency exists and is apparently by design. (Though really, as a cross-browser framework this seems like exactly the sort of thing jQuery should make consistent across browsers.)