I have a table and I create rows on the fly with:
$('#AjaxResultTable > tbody:last').append('<tr class="row"><td class="expandResult" title="Click to expand/collapse">+</td>' + id + name + suburb + state + zip + '</tr>').hide().fadeIn(200);
I want to change background color on rows when I hover over them and change back when I’m not.
I tried with
$('#AjaxResultTable tr').hover(function () {
$(this).css('background-color', '#f5f5f5');
}, function () {
$(this).css('background-color', '#fff');
});
but that didn’t work so I tried with
$('#AjaxResultTable tr').live('hover', function () {
$(this).css('background-color', '#f5f5f5');
}, function () {
$(this).css('background-color', '#fff');
});
which changes the background-color when I hover over a row but it doesn’t change back to white when I’m not.
Any suggestions?
Thanks in advance.
I’d make a simple event handler that toggles a class.
JS
CSS
EDIT: Also in your example, the property should be called
backgroundColor(instead ofbackground-color)EDIT 2: .live() has a few caveats, one of which is binding with .hover(). See the API doc here.
Hope this helps!