I am using jQuery to select all anchor tags that start with a certain prefix and then call a function for each:
$('a[id^="lblMyLabel"]').each(function() {
doSomething(this.id);
});
and inside of doSomething I make an ajax call to fetch some data. I was assuming that jQuery would scan the page from top to bottom grabbing all the anchor tags starting with lblMyLabel and act on them in that order but the order seems to be random. Does anyone know how this selection takes place?
EDIT: So I agree you guys are all right that it picks the items from top to bottom. But if I stick a break point on the WebMethod responding to the ajax call it is not getting the ID’s in that order. How is that order determined?
In this case, in a modern browser, jQuery uses
allowing the browser to do the work.
In all cases other than .prev like methods jquery returns elements in the order that they appear in the document.
https://developer.mozilla.org/en-US/docs/DOM/Document.querySelectorAll