Im having some trouble with this clickable row using javascript:
http://www.fpmnky.com/test.php
The curser doesnt change to a pointer and if you click the text area of the row it does not go to the link in the code [google.com]
<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
jQuery( function($) {
$('tbody tr[data-href]').addClass('clickable').click( function() {
window.location = $(this).attr('data-href');
}).find('a').hover( function() {
$(this).parents('tr').unbind('click');
}, function() {
$(this).parents('tr').click( function() {
window.location = $(this).attr('data-href');
});
});
$('tbody tr[data-href]').css( 'cursor', 'pointer' );
$('tbody tr[data-href]').hover(function() {
$(this).css('cursor','pointer');
});
});
</script>
<body>
<table>
<thead>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr data-href="http://google.com">
<td>text</td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><a href="#">Edit</a> <a href="#">Delete</a></td>
</tr>
<tr class="even" data-href="http://google.com">
<td>text</td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><a href="#">Edit</a> <a href="#">Delete</a></td>
</tr>
<tr data-href="http://google.com">
<td>text</td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><a href="#">Edit</a> <a href="#">Delete</a></td>
</tr>
<tr class="even" data-href="http://google.com">
<td>text</td>
<td>text</td>
<td>text</td>
<td>text</td>
<td><a href="#">Edit</a> <a href="#">Delete</a></td>
</tr>
</tbody>
</table>
</body>
</html>
It appears to work on jsfiddle just fine though:
What am I missing?
cursor: pointeractually only works on hover — you might as well just set it in CSS..find('a').hover( function() { $(this).parents('tr').unbind('click');there is a better way than this...