Author: Moritz Stuhlmann, May 2008
<ul id="friends"> <li> <h1>Mike</h1> <p>Age <span class="age">31</span></p> </li> <li> <h1>Anna</h1> <p>Age <span class="age">25</span></p> </li> <li> <h1>Steve</h1> <p>He will be <span class="age">29</span> next monday.</p> </li> </ul>
$("friends").sortBySelector("H1");
$("friends").sortBySelector("SPAN.age");
Age 31
Age 25
He will be 29 next monday.
sortBySelector(element, selector[, options]) -> HTMLElement
$("friends").sortBySelector("SPAN.age", {reverse: true});
Example: If you have two H1-tags in your markup and you need to sort by the second tag, simply set the index (start counting at 0).
$("friends").sortBySelector("H1", {index: 1});
$("foo").sortBySelector("A.more SPAN.info");
$("foo").sortBySelector("H1").setOpacity(0.5);
markup with <span class="date">2008/5/1</span> works fine
Use it and share it. This code is absolutely free and can be used in any project. Please do not delete the copyright information in the javascript file.
Have fun!