Kieran Senior
Kieran Senior

Reputation: 18230

Multi-Conditional Selectors in jQuery

I'm trying to select elements with multiple conditions, for example I'm doing the following at the moment:

$('#myspan').find('input:visible').each(myfunc);

Although I know you can do things like $('#myspan input:visible') but it didn't work for me. I need to check for inputs within the span #myspan which are visible and are checked. Any ideas?

Upvotes: 1

Views: 2399

Answers (2)

cletus
cletus

Reputation: 625457

Try:

$("#myspan :checked:visible").each(function() {
    // do stuff
});

Upvotes: 6

Paolo Bergantino
Paolo Bergantino

Reputation: 488724

$('input:visible', '#myspan').find(':checked').each(function() {
    alert(this.id);
});

Should do the trick. I like seperating things because I like to think it helps jQuery parse better.

Upvotes: 2

Related Questions