RE: [css-om] CSSStyleDeclaration.parentElement

> Subject: [css-om] CSSStyleDeclaration.parentElement
>> Returns the element that host the current style declaration, if any. {
>> NOTE: This attribute is mutually exclusive with the parentRule
>> attribute, in the sense at most one of the two can return a non-null
>> value. }
>>
>> // would be great to add to the web platform, polyfilling
>> "someNode.style.someProperty" is a huge pain right now...
>
> Can you elaborate on the use case?

I want to fake support for some property. Let's say I want to support "flow-from" from the CSS Regions Spec.

The normal way to do this would be to extend CSSStyleDeclaration and define some "flowFrom" property there. However, if you want to apply this property, you need to have a reference to the element on which this property applies and you have none in the CSSStyleDeclaration interface. { NOTE: you may, for instance, want to update some HTML attribute in response to a change in style. }




My idea to work-around the lack of "parentElement" was then to override HTMLElement.prototype.style and path the "parentElement" property when the style declaration is created but... thank you Webkit for considering "style" as a magic own value property of every element, that's so helpful!

Finally, I settled on a new "myStyle" property which would return the "style" of the element but would add manually the "parentElement" property so that I can access it in my "flowFrom" getter/setter. That's a ugly hack but I can't do better for now... 		 	   		  

Received on Tuesday, 6 August 2013 17:09:05 UTC