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

210
Views
¿Por qué obtengo un valor indefinido cuando hago clic en la imagen? ¿Cómo arreglar esto?

Recibo este error (indefinido) cuando hago clic en la imagen para obtener el valor de la imagen. ¿Puede explicar la razón detrás de esto y cómo obtener y pasar el valor a la función onclick en este caso?

 <div id="fi" value="0"> <img src="first.JPG" alt="first" id="first" value="01" onclick="checkingg(this.value)"/> </div> // inside script tag function checking(img_val) { console.log(img_val); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No hay problema en su enfoque, excepto que el value no es un atributo válido en la imagen y, por lo tanto, no estará undefined . Usar atributos de datos personalizados data-* :

 function checking(img_val) { console.log(img_val); }
 <div id="fi" value="0"> <img src="https://media.istockphoto.com/photos/analyzing-samples-in-test-tube-backgrounds-picture-id1290116527?b=1&k=20&m=1290116527&s=170667a&w=0&h=51bfejWaiLIK8ZeeP7u7q0b1UINUwx3dbH86HZNNuPA=" alt="first" id="first" data-value="01" onclick="checking(this.dataset.value)"/> </div>

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!