jquery - How do I alphabetize and sub alphabetize this list? -
using jquery, how alphabetize , sub alphabetize file?
adding small sample of large html file.
<div class="two-col" id="content_well"> <ul class="hierarchyleft3 filtererd"> <li><a href= "/health-professionals/programs/center-for-outcomes-research-and-educati/pages/default.aspx"> center outcomes research , education (core)</a></li> <li> <a href="/health-professionals/programs/camp-erin/pages/default.aspx">camp erin</a> <ul> <li><a href= "/health-professionals/programs/providence-hospice-bereavement-services/pages/default.aspx"> providence hospice bereavement services</a></li> <li><a href= "/health-professionals/programs/providence-home-services/pages/default.aspx">providence home services</a></li> </ul> </li> <li><a href= "/health-professionals/programs/childrens-inpatient-care-unit/pages/default.aspx">children's inpatient care unit</a></li> <li> <a href= "/health-professionals/programs/gerry-frank-center-for-childrens-care/pages/default.aspx"> gerry frank center children's care</a> <ul> <li><a href= "/health-professionals/programs/neurodevelopmental-center-for-children/pages/default.aspx"> providence neurodevelopmental center children</a></li> <li><a href= "/health-professionals/programs/providence-pediatric-surgery/pages/default.aspx"> providence pediatric surgery</a></li> </ul> </li> <li><a href= "/health-professionals/programs/hodgkin-and-nonhodgkin-lymphoma-program/pages/default.aspx"> hodgkin , non-hodgkin lymphoma program</a></li> <li><a href= "/health-professionals/programs/labor-delivery/pages/default.aspx">labor & delivery</a></li> <li><a href= "/health-professionals/programs/lifeline/pages/default.aspx">lifeline</a></li> <li><a href= "/health-professionals/programs/nicunewborn-care/pages/default.aspx">nicu-newborn care</a></li> <li><a href= "/health-professionals/programs/omlc-cell-therapy-and-regenerative-medic/pages/default.aspx"> omlc cell therapy , regenerative medicine program</a></li> <li><a href= "/health-professionals/programs/omlc-hemorrhage-control-technology-progr/pages/default.aspx"> omlc hemorrhage control technology program</a></li> <li><a href= "/health-professionals/programs/omlc-optics-program/pages/default.aspx">omlc optics program</a></li> <li><a href= "/health-professionals/programs/omlc-tropoelastin-biomaterials-program/pages/default.aspx"> omlc tropoelastin biomaterials program</a></li> <li> <a href= "/health-professionals/programs/oregon-medical-laser-center-omlc/pages/default.aspx"> oregon medical laser center (omlc)</a> <ul> <li><a href= "/health-professionals/programs/omlc-cell-therapy-and-regenerative-medic/pages/default.aspx"> omlc cell therapy , regenerative medicine program</a></li> <li><a href= "/health-professionals/programs/omlc-hemorrhage-control-technology-progr/pages/default.aspx"> omlc hemorrhage control technology program</a></li> <li><a href= "/health-professionals/programs/omlc-optics-program/pages/default.aspx">omlc optics program</a></li> <li><a href= "/health-professionals/programs/omlc-tropoelastin-biomaterials-program/pages/default.aspx"> omlc tropoelastin biomaterials program</a></li> </ul> </li> <li><a href= "/health-professionals/programs/portland-diabetes-project/pages/default.aspx">portland diabetes project</a></li> <li><a href= "/health-professionals/programs/pregnancy-services/pages/default.aspx">pregnancy services</a></li> <li> <a href= "/health-professionals/programs/providence-acute-rehabilitation-center/pages/default.aspx"> providence acute rehabilitation center</a> <ul> <li><a href= "/health-professionals/programs/providence-rehabilitation-services/pages/default.aspx"> providence rehabilitation services</a></li> </ul> </li> <li> <a href= "/health-professionals/programs/adolescent-eating-disorders-program/pages/default.aspx"> providence adolescent eating disorders program</a> <ul> <li><a href= "/health-professionals/programs/adult-eating-disorders-treatment-program/pages/default.aspx"> providence adult eating disorders treatment program</a></li> </ul> </li> <li> <a href= "/health-professionals/programs/adolescent-inpatient-behavioral-health-t/pages/default.aspx"> providence adolescent inpatient behavioral health treatment</a> <ul> <li><a href= "/health-professionals/programs/child-inpatient-behavioral-health-treatm/pages/default.aspx"> providence child inpatient behavioral health treatment</a></li> </ul> </li> <li> <a href= "/health-professionals/programs/adult-eating-disorders-treatment-program/pages/default.aspx"> providence adult eating disorders treatment program</a> <ul> <li><a href= "/health-professionals/programs/adolescent-eating-disorders-program/pages/default.aspx"> providence adolescent eating disorders program</a></li> </ul> </li> <li><a href= "/health-professionals/programs/providence-als-center/pages/default.aspx">providence als center</a></li> <li><a href= "/health-professionals/programs/providence-arrhythmia-services/pages/default.aspx">providence arrhythmia services</a></li> <li> <a href= "/health-professionals/programs/autologous-stem-cell-transplant-program/pages/default.aspx"> providence autologous stem cell transplant program</a> <ul> <li><a href= "/health-professionals/programs/providence-cancer-center/pages/default.aspx">providence cancer center</a></li> </ul> </li> <li> <a href= "/health-professionals/programs/providence-behavioral-health/pages/default.aspx">providence behavioral health</a> <ul> <li><a href= "/health-professionals/programs/adolescent-eating-disorders-program/pages/default.aspx"> providence adolescent eating disorders program</a></li> <li><a href= "/health-professionals/programs/adolescent-inpatient-behavioral-health-t/pages/default.aspx"> providence adolescent inpatient behavioral health treatment</a></li> <li><a href= "/health-professionals/programs/adult-eating-disorders-treatment-program/pages/default.aspx"> providence adult eating disorders treatment program</a></li> <li><a href= "/health-professionals/programs/behavioral-health-adult-inpatient-treatm/pages/default.aspx"> providence behavioral health adult inpatient treatment</a></li> <li><a href= "/health-professionals/programs/child-inpatient-behavioral-health-treatm/pages/default.aspx"> providence child inpatient behavioral health treatment</a></li> <li><a href= "/health-professionals/programs/psychiatric-dialectical-behavior-outpati/pages/default.aspx"> providence psychiatric dialectical behavior outpatient therapy program</a></li> <li><a href= "/health-professionals/programs/psychiatric-intensive-outpatient-program/pages/default.aspx"> providence psychiatric intensive outpatient program</a></li> <li><a href= "/health-professionals/programs/psychiatric-outpatient-partial-hospital-/pages/default.aspx"> providence psychiatric outpatient partial hospital program</a></li> <li><a href= "/health-professionals/programs/providence-psychiatry-clinic/pages/default.aspx"> providence psychiatry clinic</a></li> <li><a href= "/health-professionals/programs/providence-substance-abuse-treatment/pages/default.aspx"> providence substance abuse treatment</a></li> <li><a href= "/health-professionals/programs/providence-youth-services/pages/default.aspx">providence youth services</a></li> </ul>
if want dive down , sort lists , sublists @ arbitrary depth, try this:
function sortitem(a, b) { return $.trim($(a).find('a').text()) > $.trim($(b).find('a').text()) ? 1 : -1; } function sortlist(root) { $(root).children('li') .sort(sortitem) .appendto(root) .children('ul') .each(function() { sortlist(this); // recurse }); } sortlist('ul.hierarchyleft3');
working (highly reduced dataset) example: http://jsfiddle.net/redler/hwhrt/2/
Comments
Post a Comment