Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6827 closed bug (wontfix)

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 (302 bytes) - added by WouterTinus 13 years ago.

Download all attachments as: .zip

Change History (6)

Changed 13 years ago by WouterTinus

Attachment: test.html added


comment:1 Changed 13 years ago by dmethvin

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

comment:2 Changed 13 years ago by WouterTinus

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


comment:3 Changed 13 years ago by WouterTinus

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)

comment:4 Changed 12 years ago by snover

Priority: undecided
Resolution: wontfix
Status: newclosed

Use .html.

comment:5 Changed 12 years ago by jitter

#7923 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.