Reputation: 1166
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
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