How to select nested DOM elements inside 'ul' element

前端 未结 3 1840
北海茫月
北海茫月 2021-02-04 06:24

I am looking for a way to collect all tags and load then in an array using Mootool 1.1 or pure javascript.

    &l
3条回答
  •  [愿得一人]
    2021-02-04 07:24

    I'm not sure if you want to limit the action somehow, but getting all anchor elements in the page is easy:

    var links = document.getElementsByTagName('a');
    

    If you want to limit your search inside an element, set an id on that element so that you can easily find it, and use the getElementsByTagName on the element:

    var links = document.getElementById('menu').getElementsByTagName('a');
    

提交回复
热议问题