#9832 closed bug (wontfix)
text(), html() and append() don't work on <style> elements in IE8
Reported by: | Owned by: | Rick Waldron | |
---|---|---|---|
Priority: | low | Milestone: | 1.9 |
Component: | manipulation | Version: | 1.6.2 |
Keywords: | 1.9-discuss | Cc: | |
Blocked by: | Blocking: |
Description
Trying to add a style definition using a style element throws an exception in Internet Explorer 8. I tried using text(), html() and append() but they all give the same error:
Line: 192 Error: Object doesn't support this property or method
Example at http://jsfiddle.net/BdU9u/
Change History (15)
comment:1 Changed 12 years ago by
Component: | unfiled → manipulation |
---|---|
Milestone: | None → 1.next |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 11 years ago by
It's a known bug. appendChild on <style> element throws exceptions. To workaround this issue use
var style = document.createElement('style'); style.styleSheet.cssText = 'h1 { color: blue; }';
http://stackoverflow.com/questions/436710/element-appendchild-chokes-in-ie http://www.quirksmode.org/bugreports/archives/2006/01/IE_wont_allow_documentcreateElementstyle.html
comment:5 Changed 11 years ago by
Keywords: | 1.9-discuss added |
---|
comment:6 Changed 11 years ago by
+1, This seems pretty fixable for 1.9 (.text()
only) and doesn't need to be in 2.0.
comment:10 Changed 11 years ago by
Milestone: | 1.next → 1.9 |
---|
comment:12 Changed 10 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | open → assigned |
comment:13 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
text() is implemented via Sizzle and adding a special case to Sizzle.getText where: elem is style and only in oldIE, return the elem.style.cssText is unreasonable. Considering we don't need this in jQuery 2.0, Sizzle shouldn't have to carry the burden.
comment:14 Changed 10 years ago by
For those of you that dont take "no" as an answer :
$.fn.extend({ 'text': function (value) { return $.access(this, function (value) { if (value === undefined) return $.text(this); if (this[0] && this[0].nodeName == 'STYLE') { if (this[0].styleSheet) this[0].styleSheet.cssText = value; else this[0].innerHTML = value; return this; } return this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) ); }, null, value, arguments.length); } });
Confirmed
http://jsfiddle.net/timmywil/BdU9u/2/
However, this works: http://jsfiddle.net/timmywil/VdmYD/1/
So it may be that style elements are readonly in IE.