Skip to content

Instantly share code, notes, and snippets.

@ricardozea
Last active April 26, 2023 01:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ricardozea/4686072 to your computer and use it in GitHub Desktop.
Save ricardozea/4686072 to your computer and use it in GitHub Desktop.
jQuery: Add/remove a class to labels with checkboxes and radio buttons and style them
//Add/remove a class to labels with checkboxes and radio buttons and style them
$('label input[type=radio], label input[type=checkbox]').click(function() {
$('label:has(input:checked)').addClass('active');
$('label:has(input:not(:checked))').removeClass('active');
});
@faisalliaqat
Copy link

Overall, the code seems to be correct and functional. It is a concise way to add and remove classes based on the state of radio and checkbox input elements.

@ricardozea
Copy link
Author

ricardozea commented Apr 26, 2023

👍🏽🙏🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment