<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Remove Lines Containing</title> <style> body { font-family: Arial, sans-serif; } .container { margin: auto; max-width: 600px; padding: 20px; } textarea { width: 100%; height: 200px; padding: 10px; box-sizing: border-box; margin-bottom: 10px; } input[type=text] { width: 100%; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; border: 2px solid #ccc; border-radius: 4px; } input[type=button] { background-color: #4CAF50; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; float: right; } input[type=button]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>Remove Lines Containing</h2> <p>Enter the text and the keyword to remove lines containing it:</p> <textarea id="myTextarea" placeholder="Enter text here..."></textarea> <input type="text" id="myKeyword" placeholder="Enter keyword..."> <input type="button" value="Remove Lines" onclick="removeLines()"> </div> <script> function removeLines() { // Get the text area and keyword input elements var textArea = document.getElementById("myTextarea"); var keyword = document.getElementById("myKeyword").value; // Split the text area value into an array of lines var lines = textArea.value.split("\n"); // Loop through the lines array and remove lines containing the keyword for (var i = 0; i < lines.length; i++) { if (lines[i].indexOf(keyword) !== -1) { lines.splice(i, 1); i--; } } // Join the lines array back into a string and update the text area value textArea.value = lines.join("\n"); } </script> </body> </html>
No comments:
Post a Comment