javascript - Add eventlistener to canvas tag -


I get the canvas tag correctly from HTML, but when I make it an event Try, console returns me unchecked typed error: there is no undefined function . I do not understand the reason.

  var x = document.getElementsByTagName ('canvas'); Console.log (x); // Print correctly elements: [canvas, item: function, named: function] x.addEventListener ("click", provision); // UnkitType Error: Undefined No Function Function (Event) {console.log ("Prova"); //};    

document.getElementsByTagName ("canvas") [0]

getElementsByTagName returns an HTMLCollection (like an array), and works on the addEventListener elements, so that you You need to select the correct index.

An optional document.query selector ("canvas") is which will return an element.

Comments

Post a Comment

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -