civiltomain
civiltomain

Reputation: 1166

I have a CSSStyleDeclaration.prototype extended, how can I acces to 'parent'

I have some custom methods for CSSStyleDeclaration. I use it so :

A_OBJECT.style.method() ;

And the code is as simple as :

CSSStyleDeclaration.prototype.method = function () {
x = this.left;
..... etc
}

My question is : How can I access to the 'object' element 'parent' of 'this' , that is : 'A_OBJECT' ???? Is it possible ? Thanks.

Upvotes: 3

Views: 288

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

In some cases, yes it is possible. For example, if you extend CanvasRenderingContext2d, then you can access this.canvas to get the "parent" canvas that the rendering context belongs to.

However, CSSStyleDeclaration has no such backreference. There is no way to find the element that your style declaration belongs to.

I would recommend extending HTMLElement instead, and using this.style to get the style object. Basically, start one level up.

Upvotes: 1

Related Questions