Method _.USort.element
Summary:
Allows you to sort a list or table body on the DOM using a callback function. The contents of each row or list item.
If you pass this a variable that's not a DOM Element of type UL
, OL
, or TBODY
an appropriate TypeError
will be thrown.
- Calling Convention:
-
_.USort.element(Element, callback)
- Parameters:
-
- Element
-
A
TBODY
,UL
, orOL
type Element object. - callback
-
The callback function used to handle the sort. This calls a normal
Array.sort
where the structure of thatArray
is as follows:If the passed Element is a
UL
orOL
theArray
consists of objects containingObject.tag
, a reference to theLI
's DOM element, andObject.data
the plain-text contents of that Element, as per _.nodeText.When working with a
TBODY
the Array again consists of objects whereObject.tag
points at theTR
's DOM element. TheObject.data
on the other hand is an Array where each element is the plain-text contents represents eachTH
orTD
in that row.
- Returns:
- Nothing
Example
HTML
<ul id="test">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
<li>Sixth</li>
</ul>
JavaScript
_.USort.element(
_d.getElementByID('test'),
function(a, b) {
return _.compare.string(a.data, b.data);
}
);
Output
• Fifth
• First
• Fourth
• Second
• Sixth
• Third
Live Examples
These demo's are also included in the distribution archive.