1 <!--HTML Structure -2 <DivID= "Test-div">3 <Divclass= "C-red">4 <PID= "Test-p">Javascript</P>5 <P>Java</P>6 </Div>7 <Divclass= "C-red c-green">8 <P>Python</P>9 <P>Ruby</P>Ten <P>Swift</P> One </Div> A <Divclass= "C-green"> - <P>Scheme</P> - <P>Haskell</P> the </Div> - </Div>
Locate as follows: The first method:
- Select <p>javascript</p>:
- var js = document.getElementById (' test-p ');
- Select <p>python</p>,<p>ruby</p>,<p>swift</p>:
- var arr = document.getelementsbyclassname (' c-red c-green ') [0].children;
- Select <p>haskell</p>:
- var Haskell = document.getelementsbyclassname (' C-green ') [1].lastelementchild;
The second method:
- var js = document.queryselector (' #test-P ');
- var arr = document.queryselectorall (' #test-div >. c-red.c-green > P ');
- var Haskell = Document.queryselectorall (' #test-div >. c-green > P ') [4];
The third method:
- Choose <p>javascript</p>: var js = document.getElementById (' test-p ');
- Select <p>python</p>,<p>ruby</p>,<p>swift</p>: var arr = Document.queryselectorall ('. c-red.c-green>p ');
- Select <p>haskell</p>: var Haskell = document.getElementById (' Test-div '). Lastelementchild.lastelementchild;
JavaScript uses DOM to get DOM node examples in HTML