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

100
Views
Is there any ways to make this code shorter?

Is there any ways to make this code shorter? I'm coding with jQuery.

<div class="js-check-container" style="padding:0 0 0 19px;">
  <img src="/assets/admin/css/img/icon-check.svg" style="display:none;" class="js-checked">
  <img src="/assets/admin/css/img/icon-form-multi-choice-off.svg" class="js-unchecked">
</div>

$('.js-unchecked').click(function() {
    $(this).slideUp(0);
    $(this).parent('.js-check-container').find('.js-checked').slideDown(0);
})
$('.js-checked').click(function() {
    $(this).slideUp(0);
    $(this).parent('.js-check-container').find('.js-unchecked').slideDown(0);
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add the same handler to both, and inside the handler, check whether the clicked element has the js-checked or js-unchecked class, from which you can generate the string to pass into .find.

$('.js-checked, .js-unchecked').click(function() {
    const justClickedChecked = this.classList.contains('js-checked);
    $(this).slideUp(0);
    $(this)
        .parent('.js-check-container')
        .find(`.js-${justClickedChecked ? 'un' : ''}checked`)
        .slideDown(0);
})
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!