-3

I only know how to use Javascript and HTML5

I have tried so many ways to clear textarea but they won't work

<textarea id="texti" placeholder="Place Text Here Or Paste Text"></textarea>

<button class="button" type="button" onclick="clear()">CLEAR</button>  
<script type="text/javascript">
function clear(){
document.getElementById("texti").innerHTML= "";
}
</script>

in the function part I have tried

document.getElementById("texti").value=0;

document.getElementById("texti").value="";

but apparently none of theme works in my code

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Cufa Tba
  • 3
  • 4

1 Answers1

1
  1. End your textarea tag
  2. Use .value
  3. Do NOT use reserved words like clear

function clearIt() {
  document.getElementById("texti").value = "";
}
<textarea id="texti" placeholder="Place Text Here Or Paste Text">XXX</textarea>

<button class="button" type="button" onclick="clearIt()">CLEAR</button>
mplungjan
  • 169,008
  • 28
  • 173
  • 236