Switching Between Unordered and Ordered Lists

You can also change an unordered list to an ordered list and back again. This sounds easy, but it's somewhat complicated. First of all, you can't change a list from unordered to ordered once it exists. The way around this is to create a brand new list, copy the old list items into the new list, remove the old list, and place the new list in its place.

Example 4-3 shows what that looks like.

Example 4-3. Toggling unordered and ordered lists
					listType = "UL"

function toggleList ()
{
    listDiv = document.getElementById("list") ...

Get Advanced JavaScript™: Insights and Innovative Techniques now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.