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

278
Views
How can I check with JQuery if a checkbox is checked and if so add a class to the parent label?

I would like, on load of the page, to check if a checkbox is :checked Then if it is, add a class to the label. I currently have the following script but it doesn't work.

$(document).ready(function() {
    $('input').is(':checked') {
        $(this).parent('label').toggleClass('label--active');
    });
});

My HTML is:

<label class="container-checkbox" for="checkOne">
    <span class="checkbox-label">Option one</span>
    <input type="checkbox" id="checkOne">
    <span class="checkmark"></span>
</label>

I can not change the DOM order as these are custom checkboxes.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I guess you can use this:

$(document).ready(function() {
    let checkboxone = document.getElementById('checkOne');
  checkboxone.addEventListener('change',function() {
    checkboxone.parentNode.classList.toggle('label--active');
  });
});

How does is work?

Everytime when the checkbox is clicked, the class 'label--active' will be added / removed.

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!