Reverse the order of the children of Node (document) : Document « Development « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Development » Document 
Reverse the order of the children of Node (document)

/*
Examples From
JavaScript: The Definitive Guide, Fourth Edition

Legal matters: these files were created by David Flanagan, and are
Copyright (c) 2001 by David Flanagan.  You may use, study, modify, and
distribute them for any purpose.  Please note that these examples are
provided "as-is" and come with no warranty of any kind.

David Flanagan
*/
<html>
<head><title>Reverse</title></head>
<script>
function reverse(n) {          // Reverse the order of the children of Node n
    var kids = n.childNodes;   // Get the list of children
    var numkids = kids.length; // Figure out how many there are
    for(var i = numkids-1; i >= 0; i--) {  // Loop through them backwards
        var c = n.removeChild(kids[i]);    // Remove a child
        n.appendChild(c);                  // Put it back at its new position
    }
}
</script>
</head>
<body>
<p>paragraph #1<p>paragraph #2<p>paragraph #3  <!-- A sample document -->
<p>                                    <!-- A button to call reverse()-->
<button onclick="reverse(document.body);"
>Click Me to Reverse</button>
</body>
</html>

           
       
Related examples in the same category
1. Output HTML in JavaScript
2. Display info in a new page
3. Recursively reverse all nodes beneath Node n, and reverse Text nodes
4. Open a new document and add some text
5. Get element by name: getElementsByName()
6. Get a specified element using getElementById()
7. Title of a document
8. Referrer of a document (URL of the document)
9. Hide Email Address
10. Convert space to URL encode
11. document last Modified Property in Another Format
12. Checking document referrer
13. Make button (control) visible or invisible
14. Opening a New URL
15.  HTML Page with Immediate Script Statements
16. Using document.write() on the Current Window
17. Using document.write() on Another Window
18. Methods and Properties of the Document Object
ww_w.__j_a___v_a_2_s__.___c_om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.