A
A
Anto2017-10-08 21:27:16
JavaScript
Anto, 2017-10-08 21:27:16

How to set the class when the checkbox is selected?

Good day.
Tell me, there is a filter on the site with a drop-down block in which there can be a field for entering numbers or checkboxes, how to make it so that when filling in the field or selecting the checkbox, the class of the filter title is set (for example, Brands), so that it would be possible to make it a different color?
I found an example, but it works so that it sets the color of the selected checkbox.

$('body').on('click', '#js-control input:checkbox', function(){
    if ($(this).is(':checked')) {
        $(this).parent().addClass('green');
    } else {
        $(this).parent().removeClass('green');
    }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2017-10-08
@Stalker_RED

$(document).on('click', '#js-control input:checkbox', function(){
    var isChecked = $(this).is(':checked')
    $(this).parent().toggleClass('green', isChecked);
});

https://jsfiddle.net/czL277q5/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question