How to select nested DOM elements inside 'ul' element

前端 未结 3 1837
北海茫月
北海茫月 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:08

    $$('.menu a')

    0 讨论(0)
  • 2021-02-04 07:16
    // for the links of the first ul.menu on the page
    var menuLinks = document.getElement("ul.menu").getElements("a");
    // or you can get all links children of all uls with class menu
    var menuLinks = document.getElements("ul.menu a");
    
    0 讨论(0)
  • 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');
    
    0 讨论(0)
提交回复
热议问题