Skip to content

Instantly share code, notes, and snippets.

@jamesflorentino
Created July 9, 2012 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesflorentino/3078240 to your computer and use it in GitHub Desktop.
Save jamesflorentino/3078240 to your computer and use it in GitHub Desktop.
Table sibling
<link href="style.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="script.js"></script>
<table class="format2" >
<thead>
<tr>
<td>Toggle visibility</td>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor rhoncus bibendum. Nunc sed enim a lacus tincidunt consequat. </td>
</tr>
</tbody>
</table>
<table class="format2" >
<thead>
<tr>
<td>Toggle visibility</td>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor rhoncus bibendum. Nunc sed enim a lacus tincidunt consequat. </td>
</tr>
</tbody>
</table>
<table class="format2" >
<thead>
<tr>
<td>Toggle visibility</td>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor rhoncus bibendum. Nunc sed enim a lacus tincidunt consequat. </td>
</tr>
</tbody>
</table>
<table class="format2" >
<thead>
<tr>
<td>Toggle visibility</td>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin porttitor rhoncus bibendum. Nunc sed enim a lacus tincidunt consequat. </td>
</tr>
</tbody>
</table>
function ready() {
$('table > thead')
.each(function(e){
$(this).siblings(':last').hide();
})
.click(function(e) {
$(this).siblings(':last').toggle();
});
}
$(ready);
body { background: #eee; color: #111; font-family: Helvetica Neue, Helvetica, sans-serif; }
table {
background: #ccc;
border: 1px solid #aaa;
width: 200px;
}
table thead {
font-size: 18px;
cursor: pointer;
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-o-user-select: none;
}
table thead:hover {
background: rgba(1,1,1,0.1);
}
table tbody {
font-size: 12px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment