2012-04-27 7 views
0
改變其他分區的背景

當懸停我試圖改變以前的div的背景,但在這裏它不是在這裏工作的鏈接代碼Jsfiddle這是我的腳本當鼠標懸停在一個文本,使用jquery

$('div a.link').hover(function(){ 

var icon = $(this).prevAll('div.icon').first();   
      icon.css({'background':'url(http://www.rangde.org/images/icons/circle_grey_hover.jpg) no-repeat', 'color':'#fff','cursor':'pointer'}); 

});   

我的HTML

<div class="icon">1</div> 
<div><a href="#" class="link">First article</a></div> 
<div class="clearfloat"></div> 
<div class="icon">2</div> 
<div><a href="#" class="link">Second article</a></div> 
<div class="clearfloat"></div> 
<div class="icon">3</div> 
<div><a href="#" class="link">Third article</a></div> 

我的CSS

.icon{background: url(http://www.rangde.org/images/icons/circle_grey.jpg) no-repeat; 
width: 92px; 
height: 97px; 
padding: 35px 0px 0px 45px; 
font-size: 14pt; 
color: black; 
font-weight: 600; 
width: 32%;float:left;} 
.link{width:60%;float:left;color:#048ccc;font-weight:600;padding-top:30px;} 
.clearfloat{clear:both;} 
​ 

回答

3
$('div a.link').hover(function(){ 
    var icon = $(this).parent().prev();   
    icon.css({'background':'url(http://www.rangde.org/images/icons/circle_grey_hover.jpg) no-repeat', 'color':'#fff','cursor':'pointer'}); 
}, function() { 
    var icon = $(this).parent().prev().css({'background':'none'}); 
});   

​ 

http://jsfiddle.net/FEdk9/9/

+0

嗨,這是工作正常,非常感謝:) – 2012-04-27 09:45:30