. Write a JavaScript function that counts the number of form elements and
displays them in an alert box
Answers
Answered by
0
Answer:
If you have a div with child input elements in it (with a class of parent):
parent = document.querySelector('.parent');
function countChildren() {
numberOfChildren = 0;
children = Array.from(parent.children);
children.forEach(child => {
numberOfChildren += 1;
})
alert('Number of child elements: ' + numberOfChildren);
}
Create a button with an onclick event of 'countChildren()'.
Hope this helps - have a great day!
Explanation:
Similar questions