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!!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.