Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the canvas element without an id?

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?

like image 609
Saad Avatar asked Aug 15 '13 14:08

Saad


1 Answers

You can use CSS selectors:

document.querySelector('#derp canvas')
like image 101
SLaks Avatar answered Sep 18 '22 02:09

SLaks