Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
Anyway to use Jquery to detect if Ajax loads certain HTML?

A friend has a site on a platform where we cannot access the source code but can add our own JavaScript. Parts of the site load with Ajax.

I need to add an element when a particular piece of HTML loads. So far I've found:

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

But because there are 4 pieces of content loaded by Ajax on the page, this element gets appended 4 times.

I've tried wrapping that in an if statement, eg:

$(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>');
  }
});

But this doesn't work - nothing appears.

Would anyone know how to I can just add 1 button?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Your condition is wrong.

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

Should be

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

When there are no elements, you have to check the falsy and then enter. add ! before your condition.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda