tags:

views:

42

answers:

3

I have a table of 3-4 columns, the central one being task names that are also links(yet another todo app..groan). Im trying to make it so that whenever the mouse hovers over any part of the table row - not just the link itself - the link will appear underlined. Its a small detail but its been annoying me like hell and i refuse to let it get the better of me now.

At first i tried jQuery with a (forgive the obvious syntax errors but this is the jist)

$('#row_in_question').hover( 
function(){ $(this).find(...the link..).toggleClass("highlighted") },
function(){ $(this).find(...the link..).toggleClass("highlighted") }
);

with this as a styling for the a element in general

.highlighted {
text-decoration: underlined;
}

and it did indeed toggle the highlighted class on that link - however css inheritance got in the way and no visual changes made. Since i previously styled that link to have no underline when not hovered it wouldnt change the style.

So how do i go about this? I dont want the whole row to become clickable, I just want the text to become underlined.

+4  A: 

What about changing the css

$('#row_in_question').hover( 
    function(){ $(this).find(...the link..).css({'textDecoration': 'underline'}) },
    function(){ $(this).find(...the link..).css({'textDecoration': 'none'}) }
);
rahul
Good solution, if you have to support multiple browsers. Although I would prefer to toggle a class on and off rather than directly setting the CSS inline.
Stephen Orr
should have thought about doing that!! was so wrapped up in adding a class. It works great and is simple too. perfect. thank you very much.
adam
A: 

you can also whatever:hover on the TR to do it for you, although if you are already using Jquery it might be best to stick with rahuls idea.

http://www.xs4all.nl/~peterned/csshover.html

Mauro
+3  A: 

For a CSS only solution:

CSS

td a {text-decoration: none;}
td {padding:10px 5px 0 5px;}
tr:hover a {text-decoration:underline}

HTML

<table>
     <tbody>
    <tr>
        <td>aaa</td>
        <td><a href="#">bbb</a></td>
        <td>ddd</td>
     </tr>
    <tr>
        <td>aaa</td>
        <td>bbb</td>
        <td><a href="#">ddd</a></td>
     </tr>
  </tbody>
 </table>
Emily
This would work, but not in IE6 (and possibly not IE7 either, but I can't confirm that). The reason being that IE6 only supports the :hover pseudo-class on A tags, not any other element.
Stephen Orr
thanks emily for the tip, im looking for the most cross browser friendly solution here so ive given it to rahul. thank you once again.
adam