Skip to main content

Bug Tracker

Side navigation

#6827 closed bug (wontfix)

Opened July 26, 2010 08:46AM UTC

Closed October 19, 2010 01:01AM UTC

Last modified January 08, 2011 01:41AM UTC

Inconsistent behaviour in .text() on script elements

Reported by: WouterTinus Owned by:
Priority: undecided Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: text, IE8 Cc:
Blocked by: Blocking:

When the .text() function is called on a script element, IE8 returns an empty string ''. Firefox, Opera and Chrome (latest versions) do however return the content. IE8 has no problem accessing the desired output through its .innerHTML property.

(Reason for filing this bug: we are using <script type="text/html"> tags to hide our rendering templates from the likes of the W3C validator and Google).

Attachments (1)
  • test.html (0.3 KB) - added by WouterTinus July 26, 2010 08:47AM UTC.


Change History (5)

Changed July 28, 2010 02:57AM UTC by dmethvin comment:1

summary: Inconsistant behaviour in .text()Inconsistent behaviour in .text() on script elements

Changed July 29, 2010 07:57PM UTC by WouterTinus comment:2

The problem seems to be that while other browsers report a text node as child of <script>, the DOM implementation of IE does not. Here's a rough patch for the problem, starting from line 3436, that should at least work for IE8, FF3.6 and Chrome. Haven't tested other browsers.

Get the text from text nodes and CDATA nodes

if ( elem.nodeType === 3 || elem.nodeType === 4 ) {

ret += elem.nodeValue;

Special case for script nodes

} else if ( elem.tagName === 'SCRIPT' ) {

ret += elem.text;


// Traverse everything else, except comment nodes

} else if ( elem.nodeType !== 8 ) {

ret += getText( elem.childNodes );


Changed July 29, 2010 08:11PM UTC by WouterTinus comment:3

Actually there is several things you can return instead of elem.text:

  • '' (in case you consider IE8 behavior correct)
  • elem.text
  • elem.innerHTML

But not:

  • elem.innerText (undefined in FF, '' in IE8)
  • elem.textContent (undefined in IE8)
  • elem.nodeValue (null in IE8)

Changed October 19, 2010 01:01AM UTC by snover comment:4

priority: → undecided
resolution: → wontfix
status: newclosed

Use .html.

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

#7923 is a duplicate of this ticket.