How does this work in regard to arguments (I’m using this in sorting a select box):
$(this).html( $("option", $(this)).sort( function(a, b) {return a.text == b.text ? 0 : a.text < b.text ? -1 : 1}));
If $(this) represents a “select” menu, argument is a collection of sorted “option” values. Or is there a better/cleaner way to explain what’s happening?
You asked for an explanation, here’s a plain English explanation:
Equivalent jQuery for your code, with variable names to help you see what’s happening:
The sorting that occurs is a JavaScript method, read about it here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort