Created
May 21, 2026 17:33
-
-
Save rauschma/ab041e737b712590f7bc6b4b11cc2a49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Reverse children</title> | |
| </head> | |
| <body> | |
| <div id="container"> | |
| <div>Child A</div> | |
| <div>Child B</div> | |
| <div>Child C</div> | |
| <div>Child D</div> | |
| </div> | |
| <button>Reverse</button> | |
| <script type="module"> | |
| document.querySelector('button').addEventListener( | |
| 'click', | |
| () => { | |
| const container = document.getElementById('container'); | |
| const children = Array.from(container.childNodes); | |
| for (const ch of children) { | |
| container.removeChild(ch); | |
| } | |
| children.reverse(); | |
| for (const ch of children) { | |
| container.appendChild(ch); | |
| } | |
| } | |
| ); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment