2

I am making a calculator in HTML. I want to clear the result using the Clear button. But the thing does not work.

This is my HTML code for the clear button:

<button onclick="clear()">C</button>

This is my Javascript code for this function:

function clear()
{
    document.getElementById('text').innerHTML=" ";//text is the ID of the paragraph tag which holds the string which the user has passed
    document.getElementById('answer').innerHTML=" ";//answer is the ID of the paragraph tag which shows the answer
}

Please Help me out. Thanks in advance!!

1 Answers1

4

As mentioned in this question(How do I clear inner HTML) you‘re overwriting document.clear, which might lead to errors.

Consider choosing another name for your function.

MoPaMo
  • 517
  • 6
  • 24