I am trying to pass this element to a function by making somethin" /> I am trying to pass this element to a function by making somethin" /> I am trying to pass this element to a function by making somethin"/>

How to pass getElementById(#canvas) as a parameter to a function in polymer

91 Views Asked by At

I have a template code like this:

<img id ="canvas" src="../images/carsimage.jpg" />

I am trying to pass this element to a function by making something like getElementById in javascript. But I am getting an error with 'this.$.canvas'

initDraw(this.$.canvas);

initDraw(canvas) {
}
1

There are 1 best solutions below

0
Arnau On

You should define a better question and provide a codepen/fiddle/whatever, but assuming you want to call it from a component, you forgot to call the initDraw function using this. In Polymer v2 would be something like this:

ready() {
   super.ready();
   this.initDraw(this.$.canvas);    //here call this.functionName
}

initDraw(canvas) {
   console.log('canvas = ', canvas);
}