According to jQuery documentation
ID Selector
Description: Selects a single element with the given id attribute.
When you have this markup
<div id="mydiv"></div>
And you do
alert($('#mydiv')); // displays "[Object]"
alert($('#mydiv')[0]); // displays "[HTMLDivElement]"
Since we expect 1 element, what is the explanation for the array notation? What makes the two different?
NOTE: Am more concerned about why we have array/collection of DIV when we only expected one.
Is [Object] = Array {HTMLDivElement}. What is the structure of [Object]?
$('#mydiv')//–> displays[Object]because it is jQuery object.$('#mydiv')[0]// displays[HTMLDivElement]because it is a DOM elementThere is a good explanation on why it is an array https://stackoverflow.com/a/7183714/297641