Selecting only first-level elements in jquery

前端 未结 10 2200
忘了有多久
忘了有多久 2020-11-28 03:14

How can I select the link elements of only the parent

    from a list like this?

    • Link
10条回答
  •  庸人自扰
    2020-11-28 03:46

    Once you have the initial ul, you can use the children() method, which will only consider the immediate children of the element. As @activa points out, one way to easily select the root element is to give it a class or an id. The following assumes you have a root ul with id root.

    $('ul#root').children('li');
    

提交回复
热议问题