Count the Elements in a Div using JavaScript

 

following is  the examples in this article.

let someElement = document.getElementById('someId');

let allChildren = someElement.getElementsByTagName('*').length;
console.log(allChildren); 


// another way
let directChildren = boxsomeElement.children.length;
console.log(directChildren); 

Tags:

Share:

Related posts