Skip to main content

Bug Tracker

Side navigation

#12406 closed bug (duplicate)

Opened August 27, 2012 11:42AM UTC

Closed September 05, 2012 02:15AM UTC

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

Reported by: regardingscot@gmail.com Owned by: regardingscot@gmail.com
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.

Attachments (0)
Change History (5)

Changed August 27, 2012 01:58PM UTC by timmywil comment:1

component: unfiledmanipulation
owner: → regardingscot@gmail.com
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.

Changed August 27, 2012 02:07PM UTC by regardingscot@gmail.com comment:2

status: pendingnew

http://jsfiddle.net/Wvasc/

because it is hard to paste 3 lines

Changed August 27, 2012 02:48PM UTC by dmethvin comment:3

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

Changed August 27, 2012 03:44PM UTC by regardingscot@gmail.com comment:4

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.

Changed September 05, 2012 02:15AM UTC by mikesherov comment:5

resolution: → duplicate
status: newclosed

Duplicate of #9832.