This is my code:
$myDiv = $('<div>1</div>');
$myDiv.each(function () {
console.log(this.html());
});
It produces an error because this should be $(this). But wait. Isn’t $myDiv a jQuery object in the first place, so that this must also be a jQuery object. If so, why should I wrap this inside of $( )?
A jQuery object is more or less an array of regular DOM elements.
eachiterates over these.thisis just a DOM element whereas$(this)generates a one-element array of DOM elements with access to the jQuery API functions.