Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://developer.mozilla.org/en-US/docs/DOM/HTMLCanvasElement" rel="nofollow"><code>getContext</code></a> is a method of the canvas element, not a jQuery method.</p> <p>Any object you see looking like <code>$(...)</code> is a jQuery object, and you can only access jQuery methods and properties from that object. To access the underlying element of a jQuery object, you can dereference it like an array. e.g. The first element in a jQuery object would be <code>$(...)[0]</code>, and so on.</p> <p>Within the context of the <code>each</code> loop, the object you labeled as <code>element</code> is in fact the HTML element (in this case the canvas element), which is why that line works. <code>this</code> and <code>element</code> are synonymous there, so you can use either one. <code>$(this)</code> and <code>$(element)</code> are both jQuery objects however.</p> <p>Likewise, in your second example, <code>$('#content #'+i)</code> references a jQuery object, and <code>$('#content #'+i)[0]</code> gives you the underlying DOM element.</p> <pre><code>$('#content #'+i)[0].getContext("2d"); //yields appropriate result </code></pre> <hr /> <h3>As a general note</h3> <p>The error message <code>Object xyz has no method 'abc'</code>, or something similar, which you no doubt received when you attempted to invoke <code>getMethod</code> on the jq object, generally suggests you're chaining a method on to something whose structure you're misunderstanding—and is generally a good sign you should go and consult the API for the object you're working with. Logging the object to the console usually also gives good insight into it's structure, and in this case doing so would've told you that you weren't actually operating on the canvas.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload