简体   繁体   中英

How Do I Select a `td` Element in a Row That Has a Checkbox That is Checked?

I have a table that looks somethings like this:

<table>
  <tr class="row even">
    <td><input type="checkbox" /></td>
    <td class="name">foo</td>
    <td class="metric">22</td>
  </tr>

  ...etc

What I want to do is get an array of all td.metric only in rows that have the checkbox checked. This didn't work out as expected:

var ticks = $.map($("tr td input:checked td.metric"), function(v,i){ return ... }); 

Use the :has selector:

$('tr:has(input:checked) > .metric');

http://jsfiddle.net/RqjFX/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM