Bug Tracker

Opened 12 years ago

Closed 10 years ago

Last modified 9 years ago

#9832 closed bug (wontfix)

text(), html() and append() don't work on <style> elements in IE8

Reported by: paul.dixon@… 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 Timmy Willison

Component: unfiledmanipulation
Milestone: None1.next
Priority: undecidedlow
Status: newopen

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.

comment:2 Changed 11 years ago by anonymous

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:3 Changed 11 years ago by sindresorhus

#11486 is a duplicate of this ticket.

comment:4 Changed 11 years ago by mikesherov

#12406 is a duplicate of this ticket.

comment:5 Changed 11 years ago by mikesherov

Keywords: 1.9-discuss added

comment:6 Changed 11 years ago by dmethvin

+1, This seems pretty fixable for 1.9 (.text() only) and doesn't need to be in 2.0.

comment:7 Changed 11 years ago by gibson042

#12679 is a duplicate of this ticket.

comment:8 Changed 11 years ago by mikesherov

+1, yup

comment:9 Changed 11 years ago by gnarf

+1, If there's a fix and it's not huge, lets fix it.

comment:10 Changed 11 years ago by mikesherov

Milestone: 1.next1.9

comment:11 Changed 11 years ago by dmethvin

#12909 is a duplicate of this ticket.

comment:12 Changed 10 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: openassigned

comment:13 Changed 10 years ago by Rick Waldron

Resolution: wontfix
Status: assignedclosed

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 gern

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

comment:15 Changed 9 years ago by gibson042

#15183 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.