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

125
Views
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 answers
Answer question

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 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!