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

前端 未结 4 574
醉话见心
醉话见心 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:46

    Probably in the order it finds them, a selector pretty much traverses the DOM and when it finds an element that matches, puts it in an array.

    You could maybe do a test by having say 5 textboxes with id's of "textbox_n" where n is a number, then alert the list and see what you get?

提交回复
热议问题