cyprian cyprian - 6 months ago 23
Javascript Question

Undefined value after using .parentElement

I don't know why but when I use

.parentElement
I get undefined but in Chrome debbuger I see that there is form, where is the bug?

$('.ZamIlosc').each(function () {
var tdstan = $(this).parentElement;
// ...forward code

Answer

Either use this.parentElement (an attribute of the element) or $(this).parent() (jQuery's function to get the parent element).

By surrounding this with $( ) you're turning it into a jQuery object, which requires the usage of .parent() instead of .parentElement.