A
A
Alexey2020-04-14 14:03:01
JavaScript
Alexey, 2020-04-14 14:03:01

Error .getAttribute is not a function, I don't understand why?

<tab-panel>
   <div data-tabname="one">Tab one</div>
   <div data-tabname="two">Tab two</div>
   <div data-tabname="three">Tab three</div>
</tab-panel>

<script>
function asTabs(node) {
let nArr = Array.from(node.childNodes);
nArr.map(node => {
console.log(node.getAttribute("data-tabname");
//далее другие манипуляции
});
};
asTabs(document.querySelector("tab-panel"));
</script>


I'm slowly learning js. The collection was transferred to an array using Arroy.from
When iterating over in the map method, an error occurs. How to fix?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-04-14
@Evelate

childNodes includes text nodes that do not have attributes,
replace with children

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question