Answers for "how to determine if an html element has child"

1

check if an HTML element has any children

if (element.hasChildNodes()) {
    // It has at least one
}
Posted by: Guest on May-20-2021
1

check if element has specific child javascript

var hasChild = parentDiv.querySelector("#child2") != null;
//The querySelector() method lets you search the subtree beneath the 
//starting element using the given CSS selector string. If the element is found,
// its DOM node is returned.
Posted by: Guest on July-16-2021

Code answers related to "how to determine if an html element has child"

Code answers related to "Javascript"

Browse Popular Code Answers by Language