Get element without id

5

I have div , and within it a canvas without id and other elements .

<div id="itens">
   ...
   <canvas></canvas>
   ...
</div>

How can I get canvas using JQuery ?

    
asked by anonymous 20.08.2015 / 16:31

1 answer

4

If you need the canvas inside the element #itens

1) $('#itens canvas') selects all canvas within element $itens

2a) To return only the first (or single) use $('#itens canvas').get(0) or $('#itens canvas')[0]

2b) Or, as suggested by @JefersonAssis in the comments:

  

$ ('# canvas items: first-child')

If you want all canvas elements

1) $('canvas') selects all the canvas on the page

2a) To return only the first (or single) use $('canvas').get(0) or $('canvas')[0]

2b) Or, as suggested by @JefersonAssis in the comments:

  

$ ('# canvas items: first-child')

    
20.08.2015 / 16:45