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

126
Visualizações
Trying to invoke onchange method set by jQuery

In my code, I am setting a change listener on my checkboxes here

  $(".section").change(function() { 
       if($(this).is(":checked")) {
        $("." + this.id).show();
        ...

Now I am trying to do a "code-driven" click on the checkbox, and I have

  $(".secTitle").click(function(e) {
    var elem = this;
    while(elem) {
      if (elem.className && elem.className.indexOf ('DOC_SECTION') != -1) {
        var clzes = elem.className.split(" ");
        var clzIdx = 1;
        if (elem.getAttribute('closeSecClassIdx')) {
          clzIdx = parseInt(elem.getAttribute('closeSecClassIdx'));
        }
        var chk = document.getElementById(clzes[clzIdx]);
        chk.checked = false;
        alert(chk.onchange);
        //chk.changed();
        break;
      }
      else {
        elem = elem.parentNode;
      }
    }
  });

I know that I have the right element, as chk.checked = false; is working correctly. After that I'm trying to invoke the change method set earlier but my alert is showing 'undefined'.

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

0

You can trigger the change event by calling $(chk).change(). Below I've created a little prototype that shows binding to the change event and invoking it.

jQuery(function($) {
    // bind to the change event
    $("input").change(function() {
        console.log('change triggered!');
    });
    
    // now trigger it
    $("input").change();    
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" />

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