1

I want to execute something after rendering the DOM tree.

I'm trying to build an app by using canvas. In this process,

I try to do below.

getElementsByTagName('canvas');

But there is nothing.

If I surround my code with this.

setTimeout(...,0)

It will work.

I think it is caused by rendering. How to execute after render?

Kaiido
  • 123,334
  • 13
  • 219
  • 285
原裕貴
  • 37
  • 5

1 Answers1

0
document.body.onload = function() {
  var canvas = getElementsByTagName('canvas')[0]
  // do something with canvas
}
Rob Kwasowski
  • 2,690
  • 3
  • 13
  • 32