Can you explain a bit more what you’re trying to do here, and what you think the line of code should be doing? A node name is a string. And it’s just a [read-only] property, it can’t return anything else. So just need a bit more clarity re your intent - what attribute, for example?
At the minute you are selecting the element with ID id02 and as far as I can see, attempting to set the HTML inside it to the node name of one (?) of the nodes in the document - there’s an issue with your syntax there but I don’t want to offer any advice before I’m sure I understand what you’re trying to do.
Right, so node name, all you can get is the name. It’s like an array, and asking for array.length - all you can get is the length, it doesn’t lead to anything else.
What is the.purpose of getting the name of the attribute (note this has nothing to do with node names), and do you you want the attributes for the element with that ID? If you want all the attributes of an element, then
myElement.attributes
Will give you a nodelist of all of them
for (let [key, val] of myElement.attributes) {
console.log(key)
}
Or do you want to check if an element has an href and print href if so?
if (myElement.href)
console.log(myElement.href)
else
console.log('No href!')
I’m not sure how to explain this more clearly. nodeName is a read-only property of DOM nodes. It’s just a capitalised string that is a code that represents the element type, so for a <p> it is P, for a <div> it is DIV and so on. It gives you absolutely no other information, you can’t find out any attributes or whatever from it. Unless I’m missing something here, the node name has zero use to you.
If you have an element selected, you can get its attributes via theElementISelected.attributes. With an href, you can get the value of the href property using theElementISelected.href
Again though, why are you trying to get the name of the property href?