Selecting only first-level elements in jquery

前端 未结 10 2215
忘了有多久
忘了有多久 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 04:08

    You can also use $("ul li:first-child") to only get the direct children of the UL.

    I agree though, you need an ID or something else to identify the main UL otherwise it will just select them all. If you had a div with an ID around the UL the easiest thing to do would be$("#someDiv > ul > li")

提交回复
热议问题