2010-12-14 67 views
0

我剛剛開始使用jQuery,遇到了一些麻煩。jQuery擺脫:懸停下劃線?

得到了一張縮略圖表,我想讓每個單元格在我將鼠標懸停在其中的圖片上時突出顯示。得到那部分工作。但我也希望單元格內的圖片不要有下劃線 - 這是從樣式表a:hover{text-decoration:underline}繼承而來的。這是我卡住的地方,我不認爲我設定的是正確的。

我需要使用內聯樣式,所以我的jQuery的樣子:

$('[name*=thumb]').hover(
    function() { 
    //as we hover over an item, change it's background, attempt to vaquish pesky underline 
    $('#' + $(this).attr('id').replace('thumb', 'thumbcontainer')).css('background-color', '#cccccc'); 
    $('#' + this).css('text-decoration', 'none'); //doesn't work : (
    }, 
    function() { 
    //fix bgs of items we're not hovering on 
    $('#' + $(this).attr('id').replace('thumb', 'thumbcontainer')).css('background-color', '#ffffff'); 
    } 
); 

我的HTML看起來像這樣:

<td name="thumbcontainer8" id="thumbcontainer8"><a href="#" name="thumb8" id="thumb8"><img src="..." /></a></td> 
<td name="thumbcontainer9" id="thumbcontainer9"><a href="#" name="thumb9" id="thumb9"><img src="..." /></a></td> 

回答

2

什麼:

$(this).css('text-decoration', 'none'); 
3

這是不是規則在樣式表做的伎倆?

a:hover img{text-decoration:none} 
+1

我必須使用內聯樣式。 – 2010-12-14 18:02:52

+1

這是CSS的用途。使用jquery添加/刪除css標籤 – 2010-12-14 18:03:20