Ad Code

How to create word counter web pgae using html

Advertisements
To create a simple word counter web page using HTML, you can use the following code:

<!DOCTYPE html> <html> <head> <title>Word Counter</title> </head> <body> <h1>Word Counter</h1> <textarea id="textInput"></textarea><br> <button id="countBtn">Count Words</button><br><br> <p>Number of Words: <span id="wordCount"></span></p> <script> const countBtn = document.querySelector("#countBtn"); const textInput = document.querySelector("#textInput"); const wordCount = document.querySelector("#wordCount"); countBtn.addEventListener("click", function() { const words = textInput.value.trim().split(/\s+/); wordCount.textContent = words.length; }); </script> </body> </html>


This code creates a simple HTML page with a text area for input and a button to count the number of words in the input. The JavaScript code listens for a click event on the button, splits the input text into words using split() method, and updates the word count displayed on the page.

how to create word counter big text area web pgae using html

To create a word counter web page with a large text area using HTML, you can use the following code:

<!DOCTYPE html>
<html>
  <head>
    <title>Word Counter</title>
    <style>
      textarea {
        width: 500px;
        height: 300px;
      }
    </style>
  </head>
  <body>
    <h1>Word Counter</h1>
    <textarea id="textInput"></textarea><br>
    <button id="countBtn">Count Words</button><br><br>
    <p>Number of Words: <span id="wordCount"></span></p>

    <script>
      const countBtn = document.querySelector("#countBtn");
      const textInput = document.querySelector("#textInput");
      const wordCount = document.querySelector("#wordCount");

      countBtn.addEventListener("click", function() {
        const words = textInput.value.trim().split(/\s+/);
        wordCount.textContent = words.length;
      });
    </script>
  </body>
</html>


This code is similar to the previous code, but with the addition of some CSS styles to make the text area larger. The CSS width and height properties are used to set the size of the text area.
Download Link
Advertisements

Post a Comment

0 Comments