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!)

Javascript todo-list sorter (See related posts)

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>

You need to create an account or log in to post comments to this site.


Related Posts