Please explain the [0] in this code:
$(function (){
var $cont = $('#cont');
var $el = $cont.children(':first'), el = $el[0];
});
I tried some ‘alert’ to find the text, but i don’t really understand why we precise the index, while we already know that we’re pointing on the “first” children of the div… ?
In the above example,
$elis a jQuery object containing one element which is ensured by the:firstselector. On the other hand,elcontains the underlying DOM element of the first (and only) item in the$eljQuery object.You can access native properties of the
elvariable, like.innerHTML. You can use all jQuery supported operations on$el, like$el.html().