Which object exactly returns 'this' in jQuery.each?

I tested for hours different codes for moving the DOM.

$(element).children('.classelement').each(function(){
    alert(this) // returns "object HtmlDivElement"
    alert(this.lastChild) // returns "object Text"

    // NOTE: The last child is a <a> element
});

Why this.lastChildreturns object Text? If it thisreturns a DOM object, why lastChildnot?

And after I have the following question: what object returns thisinside a .each?

What should I do to get the DOM object in this case?

+3
source share
1 answer

lastChildreturns the last node of any type in the element (including a space, tab, or new line recorded in the file). If you need the latest HTMLElement inside an element, you should use lastElementChild.

+5
source

All Articles