Clear value HTML JAVASCRIPT how do do it

Learn how to create clear value with an input field and textarea field.
1 input field :


<!-- When the input field gets clicked, replace its current value with an empty string -->

<input type="text" onfocus="this.value=''" value="Rose">



Textarea clear button field by clearing the text you put on the box with one click


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8" />

    <textarea id="message" name="message" rows="5" cols="33"></textarea>

    <button id="btn">Clear value</button>

    <script src="index.js"></script>

  const textarea = document.getElementById('message');

//  Clear textarea value
textarea.value = '';

//  Clear textarea value on click
const btn = document.getElementById('btn');

btn.addEventListener('click', function handleClick() {
  //  log value before clearing it

  //  clear textarea value
  textarea.value = '';



Comments :

Post a Comment