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

238
Views
Error de referencia no capturado: estoy tratando de usar un botón con el método OncLick en JavaScript, pero sigo recibiendo un error.

Estoy tratando de recibir un mensaje cuando se hace clic en el botón, pero sigo recibiendo errores en mi consola y el botón no funciona. Es mi primera semana aprendiendo js.

El error que estoy recibiendo en la consola es:

Error de referencia no detectado: la compra no está definida en HTMLButtonElement.onclick (shoe.html:10:32)

 let showMessage = document.getElementById("error=el"); let message = " sorry some error!" function purchase(){ //console.log('clicked'); showMessage.textContent = message; } purchase();
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button onclick="purchase()">Purchase</button> <p Id="error-el"></p> </body> </html>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Hay algunos pequeños errores en el código que arreglé,

  • El atributo id debe estar en minúsculas
  • Al obtener el elemento por la función Id, está buscando error=el en lugar de error-el . El problema aquí era el = en lugar de -

 let showMessage = document.getElementById("error-el"); let message = " sorry some error!" function purchase(){ showMessage.textContent = message; }
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <button onclick="purchase()">Purchase</button> <p id="error-el"></p> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

Para usar JavaScript en su HTML, debe cargar el script desde otro archivo usando una etiqueta <src> o escribirlo directamente en el archivo .html con una etiqueta <script> .

about 4 years ago · Juan Pablo Isaza Report
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!