Bug Tracker

Opened 7 years ago

Closed 7 years ago

#12406 closed bug (duplicate)

using text function on style elements produces error in IE7/8

Reported by: regardingscot@… Owned by: regardingscot@…
Priority: low Milestone: None
Component: manipulation Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

Description

jQuery versions tested: 1.7.2, 1.8.0 OS: Window 7, windows Vista, Linux

How to reproduce

var style = $('<style id="mystyle"></style>'); $('head').append(style); style.text('body {background-color: red;}');

works in ie9, ie10, ff 11+, chrome gives errors in ie7 and ie8, error being that one cannot append child text node to the style element. The solution would be to set styleSheet.cssText, however jquery should have abstracted this away.

Change History (5)

comment:1 Changed 7 years ago by timmywil

Component: unfiledmanipulation
Owner: set to regardingscot@…
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/. Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 7 years ago by regardingscot@…

Status: pendingnew

http://jsfiddle.net/Wvasc/

because it is hard to paste 3 lines

comment:3 Changed 7 years ago by dmethvin

Status: newpending

We get a LOT of bugs where people post code snippets, and often when we take the time to create a jsfiddle it seems to work fine. So after 10 minutes of trying with several browsers and fiddling to see if "maybe it's this situation" or "perhaps I can recreate it with that" we reply on the ticket, only to be told that it only occurs in an obscure situation like only with this specific plugin, and/or only in IE6. So we prefer that the reporter make the test case so it's exactly what you intended and it won't be affected by transcription or misinterpretation on our part.

As for the test case, this has been true since the beginning of jQuery. The inside of a style element does not contain DOM elements. Are you only expecting to have .text() work, or are you expecting .append() to work as well to add rules? How about other methods like .appendTo?

Have you tried a plugin? I can't vouch for these but you can see by the ages that these have been around to solve the problem for quite a while.

http://www.burnbright.co.nz/resources/globalstylesheet-jquery-plugin/

http://flesler.blogspot.com/2007/11/jqueryrule.html

comment:4 Changed 7 years ago by regardingscot@…

Status: pendingnew

The problem is that standard compliant browsers understand the following:

document.getElementsByTagName('style')[0].textContent = 'whatever';

What I was expecting is that jQuery hides browser differences and allows common tasks to be performed based on those abstractions, i.e. host environment independently.

I found the bug in closure library and was just checking other libraries in the ecosystem, thus far none implements this correctly, although everyone is stating support for IE7+. I just assumed it should be supported case. Other than that I don't need it fixed, so feel free to close the issue.

comment:5 Changed 7 years ago by mikesherov

Resolution: duplicate
Status: newclosed

Duplicate of #9832.

Note: See TracTickets for help on using tickets.