Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Why isn't JavaScript and HTML letting me use the word 'clear' as a name of the function?

I have the following code in which when you enter a number in the input and press the button multiply by 3, it gives the result. And when you press clear, it should clear the result (the empty p tag). I have given the value clear() to the clear button and have also used clear() to call the function in JavaScript, but when I run the code and then try the Clear button, it doesn't work. Here is the code:

function multiplyBy3(){
document.getElementById('result').innerHTML = document.getElementById('xx').value*3;
}
function clear(){
document.getElementById('result').style.display = "none";
}
<label for="number">Enter a number:</label>
<input id="xx" type="number">
<p id="result"></p><br>
<button onclick="multiplyBy3();">Multiply by 3</button>
<button onclick="clear();">Clear</button>




Replaced 'clear' by 'rr':

However, when I replace the word clear by another word, it does work. I replaced clear by rr in the following code and it's working perfectly fine. Here is the modified code:

function multiplyBy3(){
document.getElementById('result').innerHTML = document.getElementById('xx').value*3;
}
function rr(){
document.getElementById('result').style.display = "none";
}
<label for="number">Enter a number:</label>
<input id="xx" type="number">
<p id="result"></p><br>
<button onclick="multiplyBy3();">Multiply by 3</button>
<button onclick="rr();">Clear</button>



I also checked the Reserved words/keywords but it isn't one of them. Can anyone tell me why it isn't working?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!