Is the order objects are return by a jQuery selector specified?

前端 未结 4 569
醉话见心
醉话见心 2020-11-30 05:37

All jQuery selectors return an array of objects. Are these objects always in the same order as they are in the HTML? Can I rely on this?

4条回答
  •  一生所求
    2020-11-30 05:41

    There may be some exceptions, for example from the prevAll() documentation:

    "Given a jQuery object that represents a set of DOM elements, the .prevAll() method searches through the predecessors of these elements in the DOM tree and construct a new jQuery object from the matching elements; the elements are returned in order beginning with the closest sibling."

    http://api.jquery.com/prevAll/

提交回复
热议问题