...

Problem with Jquery hover

denhamd2
09-24-2008, 01:43 PM
Hi,

I'm trying to add a class to a <td> tag (which already has a class "description" on it) within a <tr> using JQuery when the user hovers over the <tr> tag. But my code doesn't seem to work. Please can you help? Here is my code:

$(document).ready(function(){
$(
function()
{
$("table.mytable tr").hover(
function()
{
$(this).("td.description").addClass("highlight");
},
function()
{
$(this).("td.description").removeClass("highlight");
}
)
}
)
});

Isaak
09-24-2008, 04:25 PM
This should work:

$(document).ready(function(){

$("table.mytable tr").hover(
function()
{
$(this).("td.description").addClass("highlight");
},
function()
{
$(this).("td.description").removeClass("highlight");
}
)
});

You added an unnecessary "$({ })" while you already had "$(document).ready(function(){})" and both do exactly the same thing.

denhamd2
09-24-2008, 04:48 PM
thanks but this didn't work :( Its still not adding the class "highlight" to the "description" <td> tag, any ideas?

Bill Posters
09-24-2008, 05:37 PM
e.g.
$(document).ready(function(){

$('table.mytable tr').hover(
function() {
$(this).find('td.description').addClass('highlight');
},
function() {
$(this).find('td.highlight').removeClass('highlight');
}
)
});

Isaak
10-02-2008, 09:49 PM
Oups, forgot to add the "find" function names..

wkdown
03-16-2009, 09:52 PM
Dont you need to add a space? Else you are giving the cell a class of "descriptionhighlight" instead of "description highlight".

Eldarrion
03-16-2009, 10:47 PM
Dont you need to add a space? Else you are giving the cell a class of "descriptionhighlight" instead of "description highlight".

Nope. jQuery does that automatically, so if you're adding more than one class, they're spaced out, without you needing to remember to put a space every time you use the addClass/removeClass function.

pam009
08-04-2011, 08:50 AM
my is working now thank you!!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum