Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created September 3, 2013 05:17
Show Gist options
  • Save umidjons/6419933 to your computer and use it in GitHub Desktop.
Save umidjons/6419933 to your computer and use it in GitHub Desktop.
Select table rows that contain checked checkbox using jQuery
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Rows that contain checked checkbox</title>
</head>
<body>
<table class="_tm">
<thead>...</thead>
<tbody>
<tr>
<td><input type="checkbox" name="sel" id="chk"/></td>
<td>text 1</td>
</tr>
<tr>
<td><input type="checkbox" name="sel" id="chk"/></td>
<td>text 2</td>
</tr>
<tr>
<td><input type="checkbox" name="sel" id="chk"/></td>
<td>text 3</td>
</tr>
</tbody>
<tfoot>...</tfoot>
</table>
<script type="text/javascript" src="/js/jquery-1.10.2.js"></script>
<script type="text/javascript">
jQuery( document ).ready( function ( $ )
{
var selectedRows = $( 'table._tm' ).find( 'tbody' ) // select table body and
.find( 'tr' ) // select all rows that has
.has( 'input[type=checkbox]:checked' ) // checked checkbox element
console.log( 'selectedRows:', selectedRows );
} );
</script>
</body>
</html>
@stevenyeo99
Copy link

hai table._tm what does that mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment