Help me please.

There is a checkbox, at the mark of which you need to perform an action:

return categoryFilter('other1','1') 

If the mark is removed, you need to perform:

 return categoryFilter('other1','') 

How to implement?

    1 answer 1

     $('input[type="checkbox"]').on('change', function() { if(this.checked) { categoryFilter('other1','1'); } else { categoryFilter('other1',''); } }); 

    update

     $('input[type="checkbox"]').on('change', function() { var id = this.getAttribute('id'); if(id == undefined) return; if(this.checked) { categoryFilter('other' + id, id); } else { categoryFilter('other' + id,''); } }); 
    • oh, how quickly they answered, thanks didn’t expect it!)) I didn’t completely describe the task, there are 6 such checkboxes, each one has their own id how to tie it here?)) please forgive the dullness (( - Dimastik86
    • one
      @ Dimastik86 this script will work with all check boxes. - lampa
    • I understood that, just for each checkbox its action: 1 - categoryFilter ('other1', '1'); 2 - categoryFilter ('other2', '2'); 3 - categoryFilter ('other3', '3'); and so on - Dimastik86
    • @ Dimastik86 updated post. - lampa
    • thank you, kind man! good luck to you! - Dimastik86