in querySelector: how to get the first and get the last elements? what traversal order is used in the dom?

前端 未结 4 974
太阳男子
太阳男子 2020-12-13 08:03

in a div, have elements (not necessarily 2nd generation) with attribute move_id.

First, would like most direct way of fetching first and last elements o

4条回答
  •  长情又很酷
    2020-12-13 08:36

    :last is not part of the css spec, this is jQuery specific.

    you should be looking for last-child

    var first = div.querySelector('[move_id]:first-child');
    var last  = div.querySelector('[move_id]:last-child');
    

提交回复
热议问题