$(this) differs from 'element' parameter in the context of the $.each loop
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/2925130/jquery-equivalent-of-getting-the-context-of-a-canvas">jQuery equivalent of getting the context of a Canvas</a>  </p>
</blockquote>



<p>My Questions are:</p>

<p>1) Why does the commented code not behave like that above it (i.e why does it throw an error)?</p>

<pre><code>$(function () {
  $('#ex4').append('&lt;canvas class=can &gt;&lt;/canvas&gt;');
  $('#ex4').append('&lt;canvas class=can &gt;&lt;/canvas&gt;');
  $('#ex4').append('&lt;canvas class=can &gt;&lt;/canvas&gt;');

  $('#ex4 canvas').each(function (index, element) {
    $(this).attr("width", "125")
    $(this).attr("height", "50")

    var context = element.getContext("2d");
    //var context = $(this).getContext("2d");   error

    context.strokeStyle = "red";
    context.fillStyle = "#999900";
    context.font = "30px Arial";
    context.fillText("HTML5", 0, 35);
  });
})
</code></pre>

<p>2) How do I resolve the error (presumably the same as that above) in the analogous code below?</p>

<pre><code>$.each(data[0], function (i) {
  $('#content').append('&lt;canvas id=' + i + ' class=can &gt;&lt;/canvas&gt;');
  $('#content #' + i).attr("width", "125")
  $('#content #' + i).attr("height", "50")

  //var context = $('#content #'+i).getContext("2d"); error

})
</code></pre>
