2

I have a varible IDs with 3 checkboxes ids (#Id1, #Id2, #Id3).
So when I do $(IDs), I have the list of the checkboxes.

How to know how many checkboxes are checked? I want to trigger the click event on the checked checkboxes.

I try $(IDs + ":checked").click() but the :checked is only on #Id3.

I could do $(IDs).each(...); and do in the function the test if it's checked.
Or change the value of IDs to this : #Id1:checked, #Id2:checked, #Id3:checked.

Is there a way to do it in one line? (or easily)

Thanks

2
  • put a class in each one, make a click event in the class, get the ID and try something if($(id).is(":checked")){ } ... Commented Feb 7, 2012 at 13:32
  • You can see how to do what you want at this answer: stackoverflow.com/a/2204275/132528 Commented Feb 7, 2012 at 13:32

1 Answer 1

5

Use filter.

var $checked = $(IDs).filter(':checked');
$checked.click(function() { alert('hello'); });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.