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

398
Views
cómo llamar a id con valor <?php echo $?> en javascript

tengo div con id como este

 <div id='alert<?php echo $row['no']?>'> <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b> </div>

y necesito llamar a esa identificación en javascript,

lo intento así pero el valor no es correcto

 $("#alert<?php echo $row['no'] ?>").hide();

Como arreglarlo

gracias

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe incluir jQuery CDN

 <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <script> $("#alert<?php echo $row['no'] ?>").hide(); </script>
about 4 years ago · Juan Pablo Isaza Report

0

Supongo que tienes algo como esto:

 foreach($result as $row){ ?> <div id='alert<?php echo $row['no']?>'> <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b> </div> <script>$("#alert<?php echo $row['no'] ?>").hide();</script> <?php }

De lo contrario, si la etiqueta del script está fuera del bucle, no funcionará. Otra solución sería hacer una función, digamos hideAlert(div) y hacer algo como esto:

 <?php foreach($result as $row){ ?> <div onload="hideAlert(this)"> <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b> </div> <?php } ?> <script> function hideAlert(div){ div.hide(); } </script>

si necesita la identificación para hacer referencia a ella más tarde, simplemente puede cambiar el código de esta manera:

 foreach($result as $row){ ?> <div onload="hideAlert(<?php echo $row['no']; ?>)"> <b style='font-size:12px; color: red'>*DUPLICATE ID CUSTOMER</b> </div> <?php } ?> <script> function hideAlert(id){ $(`#alert${id}`).hide(); } </script>

Tenga en cuenta que no soy un experto en jQuery, así que no estoy muy seguro de si esto funciona, pero espero que ayude :)

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!