Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery, list of unique classes to jQuery set in same order?

Tags:

jquery

Is it possible to feed jQuery a list of unique classes and have a jQuery set returned with the elements in the same order given. It seems the default is to return in DOM order.

like image 778
christian Avatar asked Jan 23 '26 01:01

christian


1 Answers

Pass in an array of DOM nodes into the jQuery constructor to guarantee the order. Here's one way of doing it:

$($.map(array_of_selectors, function(selector) {
    return $.makeArray($(selector));
}));

You could replace the call to $ with document.getElementsByClassName, as both results would be converted into an array of elements.

like image 85
Blender Avatar answered Jan 24 '26 20:01

Blender