Native JavaScript implementations get all descendant element code instances under the specified element:
The code that implements this feature is described in this section, but it is cumbersome in terms of code volume and is used in the form of recursive recursion.
The way you say it can refer to native JavaScript gets all the elements under the specified element node section, this article looks very troublesome, then share a relatively simple way, the use of native JavaScript method to achieve this function.
The code example is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <Metaname= "Author"content= "http://www.softwhy.com/" />6 <title>Ant Tribe</title>7 <Scripttype= "Text/javascript">8 window.onload=function(){9 varObox=document.getElementById ("Box");Ten varOshow=document.getElementById ("Show"); One varnodes=Obox.getelementsbytagname ("*"); A oshow.innerhtml=nodes.length; - } - </Script> the </Head> - <Body> - <DivID= "Show"></Div> - <DivID= "box"> + <Div> - <ul> + <Li>Ant Tribe One</Li> A <Li>Ant Tribe II</Li> at <Li>Ant Tribe Three</Li> - </ul> - </Div> - </Div> - </Body> - </HTML>
The above code implements our requirements, and the parameter asterisk denotes a wildcard character that can match all types of labels.
The invocation object of the getElementsByTagName () method determines its lookup scope.
Native JavaScript implementations get all descendant element code instances under the specified element