Reputation: 16519
Does anyone know of a way to add a border to a table row with a different background color when the mouse hovers over the row?
I've been able to change the background color of the row with this:
$(document).ready(function() {
$(function() {
$('.actionRow').hover(function() {
$(this).css('background-color', '#FFFF99');
},
function() {
$(this).css('background-color', '#FFFFFF');
});
});
});
But I'm unable to add a border color. I realize borders can't be directly applied to a table row tag, but I'm hoping someone know some jQuery voodoo magic that can find the table cells within the selected row and apply some styles to those to create the border.
Thanks!
Upvotes: 13
Views: 62173
Reputation: 741
$('table.tblMenuTabls tr').hover(function(){
$(this).toggleClass('tblOverRow');
},function(){
$(this).toggleClass('tblOverRow')}
).css({cursor: 'hand'});
Where tblMenuTabls
is the table class name and tblOverRow
is CSS class with hover definition.
Upvotes: 1
Reputation: 2077
$(function() {
$('tr').hover(function() {
$(this).css('background-color', '#FFFF99');
$(this).contents('td').css({'border': '1px solid red', 'border-left': 'none', 'border-right': 'none'});
$(this).contents('td:first').css('border-left', '1px solid red');
$(this).contents('td:last').css('border-right', '1px solid red');
},
function() {
$(this).css('background-color', '#FFFFFF');
$(this).contents('td').css('border', 'none');
});
});
Upvotes: 31
Reputation: 4073
Your best bet would be to addClass and removeClass on the row. Then in your stylesheet:
.actionRow-hovered td { border-color: whatever; }
So you will actually be manipulating each of the td border colors instead. A pain, but works well enough when you get the hang of it.
Upvotes: 4
Reputation: 11395
Maybe it's a good starting point:
http://www.devcurry.com/2009/02/change-table-border-color-on-hover_27.html
Upvotes: 0