AnonyMouse
AnonyMouse

Reputation: 18650

Jquery to find more than one condition for items in a table

Hi I have a table like:

<table class="approvalstable"> 
  ... 
  <tr>
     <td class="projectapproval"> 
       <img src="../../Content/Images/stock_lock.gif" alt="locked" class="lockicon invisibleforprint" /> 
     </td>
     <td>
        <input type="checkbox" class="projectcheckbox approvalcheckbox" checked="checked" />
     </td> 
  </tr>
  <tr>
     <td class="projectapproval"> 
        <img src="../../Content/Images/stock_lock.gif" alt="locked" class="lockicon invisibleforprint" />
     </td>
     <td>
       <input type="checkbox" class="projectcheckbox approvalcheckbox" />
     </td> 
  </tr>
  <tr>
     <td class="projectapproval">
     </td>
     <td>
       <input type="checkbox" class="projectcheckbox approvalcheckbox" />
     </td>
  </tr> 
  ... 
</table> 

So far to get the number of rows without lock images in them I have:

$('.approvalstable td.projectapproval:not(:has(img.lockicon))').length

However I have a further requirement to only get the number of rows without lock images in them that also have a checked checkbox.

Ok so to get the number with checked checkboxes:

$('.projectcheckbox:checked').length;

Can anyone tell me how to combine them though? I'm trying to get the number of rows that have both no lock images in a cell and a checked checkbox in a cell within the same row.

Upvotes: 2

Views: 364

Answers (2)

j08691
j08691

Reputation: 207923

Try:

$('tr').find('img.lockicon').parents('tr').find('input.projectcheckbox:checked').length

jsFiddle example.

Upvotes: 1

pete
pete

Reputation: 25091

$('.approvalstable td.projectapproval:not(:has(img.lockicon))').filter('.projectcheckbox:checked').length should do the trick.

Upvotes: 0

Related Questions