Bug Tracker

Modify

Ticket #12406 (closed bug: duplicate)

Opened 10 months ago

Last modified 10 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 10 months ago by timmywil

  • Owner set to regardingscot@…
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to manipulation

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 10 months ago by regardingscot@…

  • Status changed from pending to new

 http://jsfiddle.net/Wvasc/

because it is hard to paste 3 lines

comment:3 Changed 10 months ago by dmethvin

  • Status changed from new to pending

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 10 months ago by regardingscot@…

  • Status changed from pending to new

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 10 months ago by mikesherov

  • Status changed from new to closed
  • Resolution set to duplicate

Duplicate of #9832.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.