How can I access the canvas element without an id?
Asked Answered
O

2

8

Using CasperJs, I'm trying to do some testing on canvas, by grabbing it and using canvas.toDataURL();. However, the canvas does not have an id, the code looks something like this:

<div id= 'derp' ...>
<canvas ...> </canvas>
</div>

Can I still get the canvas using something like

var canvas = document.getElementById(????);

or is there a better way of grabbing the canvas?

Oldcastle answered 15/8, 2013 at 14:21 Comment(0)
C
14

You can use CSS selectors:

document.querySelector('#derp canvas')
Constantino answered 15/8, 2013 at 14:22 Comment(0)
C
6

You can also list all the canvas with this:

document.getElementsByTagName('canvas')
Commonly answered 2/3, 2021 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.