Selecting a last child in javascript

后端 未结 5 583
不知归路
不知归路 2020-12-21 01:39

I have a handle on an Un-ordered List (for my example i will call the handle Var1) and would like to be able to assign its last li to a variable. I tried Lastli = var

5条回答
  •  猫巷女王i
    2020-12-21 02:03

    you can select all 'li' and take the last one. Something like:

    var myLi = document.getElementsByTagName('li');
    var lastLi = myLi[myLi.length-1];
    

提交回复
热议问题