<html>
<head>
<style>
td:nth-child(odd), th:nth-child(odd) {
background-color: #48c;
color: white;
}
table {
border-collapse: collapse;
}
</style>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script>
function scrolify(tblAsJQueryObject, height){
var oTbl = tblAsJQueryObject;
// for very large tables you can remove the four lines below
// and wrap the table with <div> in the mark-up and assign
// height and overflow property
var oTblDiv = $("<div/>");
oTblDiv.css('height', height);
oTblDiv.css('overflow','scroll');
oTbl.wrap(oTblDiv);
// save original width
oTbl.attr("data-item-original-width", oTbl.width());
oTbl.find('thead tr td').each(function(){
$(this).attr("data-item-original-width",$(this).width());
});
oTbl.find('tbody tr:eq(0) td').each(function(){
$(this).attr("data-item-original-width",$(this).width());
});
// clone the original table
var newTbl = oTbl.clone();
// remove table header from original table
oTbl.find('thead tr').remove();
// remove table body from new table
newTbl.find('tbody tr').remove();
oTbl.parent().parent().prepend(newTbl);
newTbl.wrap("<div/>");
// replace ORIGINAL COLUMN width
newTbl.width(newTbl.attr('data-item-original-width'));
newTbl.find('thead tr td').each(function(){
$(this).width($(this).attr("data-item-original-width"));
});
oTbl.width(oTbl.attr('data-item-original-width'));
oTbl.find('tbody tr:eq(0) td').each(function(){
$(this).width($(this).attr("data-item-original-width"));
});
}
$(document).ready(function(){
scrolify($('#tblNeedsScrolling'), 160); // 160 is height
});
</script>
</head>
<body>
<p>Something here</p>
<p>Something here</p>
<p>Something here</p>
<div style="width:800px;border: 1px solid black;">
<table width="100%" id="tblNeedsScrolling">
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
<th>Header 4</th>
<th>Header 5</th>
<th>Header 6</th>
<th>Header 7</th>
<th>Header 8</th>
<th>Header 9</th>
<th>Header 10</th>
</tr>
</thead>
<tbody>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
<td>row 1, cell 4</td>
<td>row 1, cell 5</td>
<td>row 1, cell 6</td>
<td>row 1, cell 7</td>
<td>row 1, cell 8</td>
<td>row 1, cell 9</td>
<td>row 1, cell 10</td>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
<td>row 1, cell 3</td>
<td>row 1, cell 4</td>
<td>row 1, cell 5</td>
<td>row 1, cell 6</td>
<td>row 1, cell 7</td>
<td>row 1, cell 8</td>
<td>row 1, cell 9</td>
<td>row 1, cell 10</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
<td>row 2, cell 3</td>
<td>row 2, cell 4</td>
<td>row 2, cell 5</td>
<td>row 2, cell 6</td>
<td>row 2, cell 7</td>
<td>row 2, cell 8</td>
<td>row 2, cell 9</td>
<td>row 2, cell 10</td>
</tr>
<tr>
<td>row 3, cell 1</td>
<td>row 3, cell 2</td>
<td>row 3, cell 3</td>
<td>row 3, cell 4</td>
<td>row 3, cell 5</td>
<td>row 3, cell 6</td>
<td>row 3, cell 7</td>
<td>row 3, cell 8</td>
<td>row 3, cell 9</td>
<td>row 3, cell 10</td>
</tr>
<tr>
<td>row 4, cell 1</td>
<td>row 4, cell 2</td>
<td>row 4, cell 3</td>
<td>row 4, cell 4</td>
<td>row 4, cell 5</td>
<td>row 4, cell 6</td>
<td>row 4, cell 7</td>
<td>row 4, cell 8</td>
<td>row 4, cell 9</td>
<td>row 4, cell 10</td>
</tr>
<tr>
<td>row 5, cell 1</td>
<td>row 5, cell 2</td>
<td>row 5, cell 3</td>
<td>row 5, cell 4</td>
<td>row 5, cell 5</td>
<td>row 5, cell 6</td>
<td>row 5, cell 7</td>
<td>row 5, cell 8</td>
<td>row 5, cell 9</td>
<td>row 5, cell 10</td>
</tr>
<tr>
<td>row 6, cell 1</td>
<td>row 6, cell 2</td>
<td>row 6, cell 3</td>
<td>row 6, cell 4</td>
<td>row 6, cell 5</td>
<td>row 6, cell 6</td>
<td>row 6, cell 7</td>
<td>row 6, cell 8</td>
<td>row 6, cell 9</td>
<td>row 6, cell 10</td>
</tr>
<tr>
<td>row 7, cell 1</td>
<td>row 7, cell 2</td>
<td>row 7, cell 3</td>
<td>row 7, cell 4</td>
<td>row 7, cell 5</td>
<td>row 7, cell 6</td>
<td>row 7, cell 7</td>
<td>row 7, cell 8</td>
<td>row 7, cell 9</td>
<td>row 7, cell 10</td>
</tr>
<tr>
<td>row 8, cell 1</td>
<td>row 8, cell 2</td>
<td>row 8, cell 3</td>
<td>row 8, cell 4</td>
<td>row 8, cell 5</td>
<td>row 8, cell 6</td>
<td>row 8, cell 7</td>
<td>row 8, cell 8</td>
<td>row 8, cell 9</td>
<td>row 8, cell 10</td>
</tr>
<tr>
<td>row 9, cell 1</td>
<td>row 9, cell 2</td>
<td>row 9, cell 3</td>
<td>row 9, cell 4</td>
<td>row 9, cell 5</td>
<td>row 9, cell 6</td>
<td>row 9, cell 7</td>
<td>row 9, cell 8</td>
<td>row 9, cell 9</td>
<td>row 9, cell 10</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |