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

170
Visualizações
Java script 'document on change select function' and 'document ready function - select change function'

We are reviewing our project and trying to make it as standard as possible along all pages. We came across some possible approaches, below described, which seems to work the same (our software is restricted to Chrome).

Are there any differences we may have not noticed?

Option A:

$(document).on('change', "#selectAAA", function () { ... }
$(document).on('change', "#selectBBB", function () { ... }

or

Option B:

$(document).ready(function () {
   $("#selectAAA").change(function () { ... }
   $("#selectBBB").change(function () { ... }
   }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Option A is for delegation from document. It is quite heavy if many elements

$(document).on('change', "#selectAAA", function () { ... }
$(document).on('change', "#selectBBB", function () { ... }

I prefer Option C for static elements

$(function () {
  $("#selectAAA").on("change", function () { ... });
  $("#selectBBB").on("change", function () { ... });
})

Or you can delegate any select - this is similar to option A

Option D

$(function () {
  $(document).on('change', "select", function () {
    if ($(this).is("#selectAAA")) {
    }
    else if ($(this).is("#selectBBB")) {
    }
  })
})
about 4 years ago · Juan Pablo Isaza 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