2012-11-08 59 views
1

我試圖添加一個簡單的懸停並單擊功能到我的頁面的一部分,它不工作。我已經完成了這百次但沒有問題,但這次是不同的,我找不到原因?jQuery .hover()和.click()不起作用

HTML:

<div class="description"> 
    <div id="wrapper"> 
     <p>bla bla bla</p> 
     <div class="linkDesc"> 
      <a href="#">bla bla bla</a> 
     </div> 
     <div class="plusSign">&nbsp;</div> 
    </div> 
</div> 

的jQuery:

jQuery(document).ready(function() { 

    $('#wrapper').hover(function() { 
     $('this').addClass('hover'); 
    }, function() { 
     $('this').removeClass('hover'); 
    }); 
    $('#wrapper').click(function(e) { 
     e.preventDefault(); 
     var urlLocation = $('this').find('.linkDesc').children('a').attr('href'); 
     window.location = urlLocation; 
    }); 
}); 
+1

這不應該的選擇不會被報價 $(this),不是$('this') –

回答

7
$('this') // You have enclosed it as as a string 
      // It will try to look for tagName called this 

應該

$(this) // Removing the Quotes should work 

唯一合法TagNames , classNames , psuedo Selectors and Id's都應該被封閉在行情 ..

Check Fiddle

+0

我應該看到它!非常感謝你 – MacFerret

+0

@MacFerret ..不客氣:) –

0

,如果你只需要添加/刪除類,那麼你可以用CSS設置懸停:

#wrapper:hover { 
    background: red; 
}