Here's a little something I was working on today. The goal was to model an HTML unordered list in JavaScript so I could easily add/remove and display elements. I haven't gotten around to actually writing all of the display methods because I haven't exactly figured out how I want to use it yet.
PS: I kinda re-remembered the toString method on this one.
PPS: Requires prototype
Example Usage:
set up the list
list1 = new List(); list1.add('a'); list1.add('b'); list2 = new List(); list2.add('b1!'); list2.add('b2!'); // nest away! list1.add(list2); list1.add('c'); list1.add('d');
li data
alert(list1.get_at(1).data);
remove li
list1.remove(4);
alert the list
alert(list1);
Download the code!
Tags: javascript, tools