current position:Home>GetElementsByTagName ('li ') whether to obtain Li elements of the same level or all Li elements in it

GetElementsByTagName ('li ') whether to obtain Li elements of the same level or all Li elements in it

2022-02-02 21:13:50 CSDN Q & A

var f=document.getElementsByClassName("ul3")[0].getElementsByTagName("li")

  • Seafood Department
    •             </ul>        </li>        <li> Food Shop             <ul class="ul5">                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>        <li> Non food department             <ul class="ul5">                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>        <li> Fruit and vegetable Department             <ul class="ul5" >                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>        <li> Clothing department             <ul class="ul5">                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>        <li> Community             <ul class="ul5" >                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>        <li> service             <ul class="ul5">                <li>                     <img src="1.jpg" class="tu"></li>                    <li> <img src="2.jpg" class="tu"></li>                    <li> <img src="3.jpg" class="tu"></li>                    <li> <img src="4.jpg" class="tu"></li>                    <li> <img src="5.jpg" class="tu"></li>                    <li> <img src="6.jpg" class="tu"></li>                                                        </ul>        </li>



Refer to the answer 1:

document.getElementsByClassName("ul3")[0] Next all li Elements




Refer to the answer 2:



Refer to the answer 3:

It's all li Elements




Refer to the answer 4:



Refer to the answer 5:

getElementsByTagName("li") Get all . What is this class not ul3 [0] Under the .




Refer to the answer 6:



Refer to the answer 7:

Are you here ul3 Under the , Depends on the front xxx.getElementsByTagName()




Refer to the answer 8:



Refer to the answer 9:

Based on the question , Give advice

  1. First understand getElementsByTagName The meaning of the word The expression is to obtain the collection of elements through the name of the tag
  2. secondly , The first is a set , What comes out is a pseudo array , Relative methods that do not have a real array , In addition to having length outside
  3. Again , According to what you wrote var f=document.getElementsByClassName("ul3")[0].getElementsByTagName("li"), for , The corresponding parent has been specified class, So what we get is li The set of is corresponding to ul3 All of the following li

If help Hope you like it




Refer to the answer 10:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022113478110.html

Random recommended