The following code snippet uses the bubble sort algorithm to sort a list of DIV elements by their content. The elements are sorted "in place" meaning that no other storage (such as an array) is used. The code "bubbles" the DIV elements by removing and inserting them to achieve alphabetical order.

<html>
<head>
<title>Bubble Sort in JavaScript</title>
    <style type="text/css">
        body { font-family: Arial; font-size: 11pt; }
        div { padding: 2px; }
        a { padding: 4px; font-weight: bold; }
    </style>

    <script language="javascript" type="text/javascript">
        function sortList(listId)
        {
            var list = document.getElementById(listId);
            var items = list.childNodes;

            for (var n = items.length; n > 0; n--)
            {
                var minIndex = getMinIndex(items, n);
                if (minIndex > -1)
                {
                    var temp = list.removeChild(items[minIndex]);
                    list.insertBefore(temp);
                }
            }
        }

        function getMinIndex(items, n)
        {
            var minText = null;
            var minIndex = -1;

            for (var i = 0; i < n; i++)
            {
                var item = items[i];
                var text = item.innerText;

                // Take into account only elements that have content.
                if (typeof (text) != "undefined")
                {
                    if (minText == null || text < minText)
                    {
                        minText = text;
                        minIndex = i;
                    }
                }
            }

            return minIndex;
        }
    </script>
</head>
<body>
    <div id="BookList">
        <div>Practical Rendering with Direct3D</div>
        <div>Algorithms</div>
        <div>Introduction to AI</div>
        <div>Data Structures</div>
        <div>Code Complete</div>
        <div>Fundamentals of Computer Graphics</div>
        <div>Game Physics</div>
        <div>Real-Time Rendering</div>
        <div>Game Engine Architecture</div>
    </div>
    <br />
    <a href="javascript:sortList('BookList')">Sort Book List</a>
</body>
</html>

Before sorting:

Practical Rendering with Direct3D
Algorithms
Introduction to AI
Data Structures
Code Complete
Fundamentals of Computer Graphics
Game Physics
Real-Time Rendering
Game Engine Architecture

After sorting:

Algorithms
Code Complete
Data Structures
Fundamentals of Computer Graphics
Game Engine Architecture
Game Physics
Introduction to AI
Practical Rendering with Direct3D
Real-Time Rendering