Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Nis Sarup http://www.nis.sarup.dk/

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

Javascript todo-list sorter

The code below will, if put in the HEAD of a page, move all LI-items that contains a -tag to the bottom of the list. Handy for TODo-lists.

        <script type="text/javascript">
                function organizeList(list) {
                      var listItems = list.getElementsByTagName("LI");
                      var len = listItems.length;
                      for (var i = 0;i<len;i++) {
                            if (listItems[i].getElementsByTagName("DEL").length > 0) {
                                list.appendChild(listItems[i]);
                                i--;
                                len--;
                            }
                      }
                  }
          window.onload = function() {
              var lists = document.getElementsByTagName("UL");
              for (var i = 0;i<lists.length;i++) {
                    organizeList(lists[i]);
              }
          }
        script>
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed