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

272
Views
De todos modos, ¿usar Jquery para detectar si Ajax carga cierto HTML?

Un amigo tiene un sitio en una plataforma donde no podemos acceder al código fuente pero podemos agregar nuestro propio JavaScript. Partes del sitio se cargan con Ajax.

Necesito agregar un elemento cuando se carga una parte particular de HTML. Hasta ahora he encontrado:

 $(document).ajaxComplete(function() { $('.booking .simple_form input[type="submit"]').hide(); $('.booking .simple_form').append('<a id="login-btn" href="#">Login</a>'); });

Pero debido a que hay 4 piezas de contenido cargadas por Ajax en la página, este elemento se agrega 4 veces.

Intenté envolver eso en una declaración if, por ejemplo:

 $(document).ajaxComplete(function() { if ($('#login-btn').length) { $('.booking .simple_form input[type="submit"]').hide(); $('.booking .simple_form').append('<a id="login-btn" href="#">Login</a>'); } });

Pero esto no funciona, no aparece nada.

¿Alguien sabría cómo puedo agregar 1 botón?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tu condición es incorrecta.

 if ($('#login-btn').length) { $('.booking .simple_form input[type="submit"]').hide(); $('.booking .simple_form').append('<a id="login-btn" href="#">Login</a>'); }

Debiera ser

 if (!$('#login-btn').length) { $('.booking .simple_form input[type="submit"]').hide(); $('.booking .simple_form').append('<a id="login-btn" href="#">Login</a>'); }

Cuando no hay elementos, hay que marcar el falso y luego entrar. añadir ! ante su condición.

about 4 years ago · Santiago Trujillo 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!