iterate over node object children
/* HTML */
/*
<ul class="navigation__secondary" id="navigation-bar">
<li class="navigation__secondary-item">
<span>Item</span>
</li>
<li class="navigation__secondary-item active">
<span>Second item</span>
</li>
<li class="navigation__secondary-item active">
<span>Third item</span>
</li>
</ul>
*/
const secondaryNavList = document.querySelector('.navigation__secondary');
/* Method 1 A (ES6) */
const secondaryNavListChildren = Array.from(secondaryNavList.children);
for (let secondaryNavListItem of secondaryNavListChildren) {
console.log(secondaryNavListItem);
}
/* Method 1 B (ES5) */
const secondaryNavListChildren = Array.prototype.slice.call(secondaryNavList.children);
for (let secondaryNavListItem of secondaryNavListChildren) {
console.log(secondaryNavListItem);
}
/* Method 2 */
const secondaryNavListChildren = secondaryNavList.childNodes;
secondaryNavListChildren.forEach((navListItem) => {
console.log(navListItem);
})
Also in JavaScript:
- get status of a user discord js
- jquery find tag and class
- firestore update map
- js convert truthy
- jquery get link href value
- javascript math methods
- lookup in mongodb array
- best react boilerplate 2019
- javascript push and concat
- javascript split
- javascript automatic click
- how to reference the bot joining a server in discord.js
- jquery if screen size
- shorthand if statment in js
- check textbox value on ng-change value == in angular
- 3 dots to get all object properties in JS
- scroll to top
- react client real ip address
- reactjs typeError: Cannot read property 'offsetHeight' of null
- how to split a string in javascript
- loop through json array python
- how to parse json in java
- js filter items by index
- documenting functions javascript