This article describes the native JavaScript implementation to get the specified elements of all descendant elements of the method, shared for everyone to reference. The implementation methods are as follows:
The usual way of looping recursion is a hassle, so share a simpler way to do this with native JavaScript methods.
The code example is as follows:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title>javascript get descendant elements </title>
<script type= "Text/javascript" >
Window.onload=function () {
var Obox=document.getelementbyid ("box");
var Oshow=document.getelementbyid ("show");
var nodes=obox.getelementsbytagname ("*");
Oshow.innerhtml=nodes.length;
}
</script>
<body>
<div id= "Show" ></div>
<div id= "box" >
<div>
<ul>
<li> element One </li>
<li> element Two </li>
<li> Element III </li>
</ul>
</div>
</div>
</body>
The code above implements our requirement that the parameter asterisk represents a wildcard character that can match all types of labels.
The invocation object of the getElementsByTagName () method determines its lookup scope.
I hope this article will help you with your JavaScript Web programming.