#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: |
Description
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)
Change History (6)
Changed 13 years ago by
comment:1 Changed 13 years ago by
Summary: | Inconsistant behaviour in .text() → Inconsistent behaviour in .text() on script elements |
---|
comment:2 Changed 13 years ago by
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
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
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
Priority: | → undecided |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Use .html
.
Testcase