1
See the following code snippet below:
var element = document.getElementById('myDiv');
console.log('element: ', element);
console.log('has tagName property: ', element.hasOwnProperty('tagName'));
console.log('all properties: ', Object.getOwnPropertyNames(element));
console.log('tagName value: ', element.tagName);
<div id="myDiv"></div>
Note that the element exists, but all attempts to verify the existence of its properties are unsuccessful. But in the end I can usually get the value of the property that, according to the checks, should not exist.
According to the documentation of MDN the function hasOwnProperty()
only returns direct properties of the evaluated object. In this case the property tagName
should not be returned?
So the property
tagName
is inherited fromObject
, then it is not a direct property of the element in question.– Woss
As stated by Anderson, the property is not in the object but in the parent object. This way you will list the properties:
Object.getOwnPropertyNames(element.__proto__.__proto__)
– Valdeir Psr
Well, thank you very much for the comments! Perhaps an answer that contemplates a bit of the basic hierarchy of objects in javascript for this specific case (an html element) is enough to end this question.
– Jedaias Rodrigues