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

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

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