<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sort Text Lines</title> <style> /* Styles for the text area */ #input-text, #output-text { width: 100%; height: 150px; padding: 10px; margin-bottom: 10px; box-sizing: border-box; } /* Styles for the buttons */ #sort-button, #clear-button { display: block; margin: 10px auto; padding: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; box-shadow: 0 4px #3e8e41; } #sort-button:hover, #clear-button:hover { background-color: #3e8e41; } </style> </head> <body> <div> <textarea id="input-text" placeholder="Enter your text here"></textarea> <button id="sort-button">Sort Lines</button> <button id="clear-button">Clear</button> <textarea id="output-text" placeholder="Sorted text will appear here" readonly></textarea> </div> <script> // Get the elements const inputText = document.getElementById('input-text'); const outputText = document.getElementById('output-text'); const sortButton = document.getElementById('sort-button'); const clearButton = document.getElementById('clear-button'); // Sort the text lines function sortLines() { // Get the lines and sort them const lines = inputText.value.split('\n').sort(); // Join the sorted lines and display them outputText.value = lines.join('\n'); } // Clear the text areas function clearText() { inputText.value = ''; outputText.value = ''; } // Add event listeners to the buttons sortButton.addEventListener('click', sortLines); clearButton.addEventListener('click', clearText); </script> </body> </html>
Comments
Post a Comment
sunil191280@gmail.com