Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

263
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda