0

display = document.getElementById('outputDiv');
display.innerHTML = 'Your Number Is: ';

function clear() {
  document.getElementById("outputDiv").innerHTML = "";
}
<input type="button" value="Calculate" onclick="calculator()">

<input type="reset" value="Clear" onclick="clear()">

<div id="outputDiv"></div>

On the reset button clicked, I would like to erase display.innerHTML='Your Number Is: ' + total;

connexo
  • 53,704
  • 14
  • 91
  • 128
zJqson
  • 31
  • 7
  • what is the issue? doesn't your code working? – Ripa Saha Nov 23 '19 at 06:43
  • I just pasted a part of the code in the website because it won't let me paste the too much in. I have a the math on top of display=. After it printed total. I have a button that is the reset button I want to erase the text that it displayed. – zJqson Nov 23 '19 at 06:45
  • Does this answer your question? [Is "clear" a reserved word in Javascript?](https://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript) – FZs Nov 23 '19 at 07:02

1 Answers1

8

Do not use clear as your function name, because due to the inline event listeners' scope, it confuses with the deprecated Document.clear().

Try some other name:

<input type="reset" value="Clear" onclick = "clearValue()">

<div id="outputDiv"></div>
<script>

  var display = document.getElementById('outputDiv');
  var total = 500;
  display.innerHTML='Your Number Is: ' + total;

  function clearValue() {
    display.innerHTML = "";
  }
</script>

More: Is “clear” a reserved word in Javascript?

FZs
  • 16,581
  • 13
  • 41
  • 50
Mamun
  • 66,969
  • 9
  • 47
  • 59
  • 2
    `clear` **is not a reserved word!!!** [Reserved keywords list](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords) – FZs Nov 23 '19 at 06:49
  • @FZs, I have updated the answer with a link, thanks:) – Mamun Nov 23 '19 at 06:59
  • 2
    While it's not a reserved keyword, it's a method of the document object, and the document object is in the function handler scope, before the window object, which explains the issue. See https://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript – Constantin Groß Nov 23 '19 at 06:59