W3C home > Mailing lists > Public > www-svg@w3.org > July 2014

Re: Accessing a sheet in a style element in an svg element

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Wed, 23 Jul 2014 15:36:58 -0700
Message-ID: <CAAWBYDD7HpRYhw=6vB0DsGBjqSaK=gWZL2sABc=67z5BGnCGZg@mail.gmail.com>
To: Lennart Borgman <lennart.borgman@gmail.com>
Cc: www-svg <www-svg@w3.org>
On Wed, Jul 23, 2014 at 3:28 PM, Lennart Borgman
<lennart.borgman@gmail.com> wrote:
> On Thu, Jul 24, 2014 at 12:18 AM, Tab Atkins Jr. <jackalmage@gmail.com>
> wrote:
>> On Wed, Jul 23, 2014 at 3:09 PM, Lennart Borgman
>> <lennart.borgman@gmail.com> wrote:
>> > Dear SVG working group!
>> >
>> > I just tried to access a sheet in a style added to an svg element:
>> >
>> >     var theSvg = document.createElementNS("http://www.w3.org/2000/svg ",
>> > "svg");
>> >     var theStyle = document.createElementNS("http://www.w3.org/2000/svg
>> > ",
>> > "style");
>> >     theSvg.appendChild(theStyle);
>> >     console.log("theStyle.sheet=", theStyle.sheet); // undefined, try
>> > adding
>> > svg to DOM
>> >     document.body.appendChild(theSvg);
>> >     console.log("theStyle.sheet=", theStyle.sheet); // still undefined
>> >
>> > As you can see this failed. I have little knowledge of this subject, but
>> > was
>> > directed here from my question here:
>> >
>> > http://stackoverflow.com/questions/24920186/how-do-i-create-a-style-sheet-for-an-svg-element
>> >
>> > I am not sure if a specification is lacking here or if this is a bug in
>> > the
>> > browsers implementation. However this must of course be a part of the
>> > specification for using CSS with SVG.
>>
>> It's not an implementation or spec bug, but it is a design bug.
>> SVGStyleElement has a slightly different interface from
>> HTMLStyleElement:
>> <http://www.w3.org/TR/SVG2/styling.html#InterfaceSVGStyleElement >
>>
>> We're attempting to pursue a tighter merge of SVG with HTML, which
>> will include just reusing HTML's <style> element instead, so they'll
>> work the same automatically.
>
> Thanks Tab, that sounds good.
>
> Is there perhaps any suggested work around at the moment?

The stylesheet still shows up in the document.stylesheets list, so you
can get at it from there.  It's just a bit harder to find, if there
are other stylesheets in the document as well - you have to check the
.ownerNode property.

~TJ
Received on Wednesday, 23 July 2014 22:37:45 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:37 UTC