Learn how to create clear value with an input field and textarea field.
1 input field :
Code;
<!-- When the input field gets clicked, replace its current value with an empty string -->
<input type="text" onfocus="this.value=''" value="Rose">
Output:
Textarea clear button field by clearing the text you put on the box with one click
Code:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /></head><body><textarea id="message" name="message" rows="5" cols="33"></textarea><button id="btn">Clear value</button><script src="index.js"></script></body></html><script>const textarea = document.getElementById('message');// Clear textarea valuetextarea.value = '';// Clear textarea value on clickconst btn = document.getElementById('btn');btn.addEventListener('click', function handleClick() {// log value before clearing itconsole.log(textarea.value);// clear textarea valuetextarea.value = '';});</script>
Output:
Comments :
Post a Comment