'Finding child node's index
I have a parent div with some nested elements in it. They have the same class name without an id.
How can I get the value of a specific child node?
Solution 1:[1]
add id to your parent element, then
let parent = document.getElementById('parentid');
let chil = parent.children;
Solution 2:[2]
In a scenario where you want the value of a single specific elements, give it an id and refer to it using document.getElementById(element's id).
If you're trying to get the value of every single nested element, you can use document.querySelectorAll(elements' mutual class name). This gives you a list of nodes (basically an array) which you can iterate over and do whatever you need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Viyan Md |
| Solution 2 | Art |
