Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: how are HTML elements ordered when I select them using jquery selector

Is there some documentation regarding the order of returned HTML elements by a jquery selector. So for example if I do

$('div.experience_entries_list input.experience_order_array').each(function() 
{
    alert(this.value);
});

, can I assume that the returned elements will come in the order that they are positioned in the html? I've checked this and it seems to be so but I want to be 100% sure before releasing the code built with this assumption :)

like image 448
Eugene Avatar asked Apr 22 '26 00:04

Eugene


1 Answers

Yes, as of jQuery 1.3.2 elements are returned in document order.

From the release notes:

Elements Returned in Document Order

This is a change to jQuery's selector engine that re-orders the returned results to be in document order, instead of the order in which the selectors were passed in. This change was done in order to be in compliance with the Selectors API specification (which jQuery uses, internally, in browsers that support it).

like image 107
Mario Menger Avatar answered Apr 23 '26 15:04

Mario Menger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!