2012-04-12 71 views
2

我想改變位於h3內的跨度類,但我無法。下面是什麼,我試圖完成一個鏈接:http://jsfiddle.net/WPxG4/9/jquery更改類

代碼:

jQuery(document).ready(function() { 
    $('h3').click(function() { 
     $(this).next('ul').toggle(); 
     $(this).next('span').toggleClass('special1', 'special'); 
     return false; 
    }).next().hide(); 
}); 

HTML:

<h3><span class="special"></span><a href="#">Heading 1</a></h3> 
<ul> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
    <li><a href="#">List one two there</a></li> 
</ul> 

回答

4

使用$(this).find('span')$(this).next('span')

+0

謝謝你,工作像魅力一樣編輯。 – mpora 2012-04-12 15:07:06

+0

@ user1238850您的歡迎^ _ ^。請記得在這裏和其他問題上選擇一個可接受的答案,如果有的話。 – Neal 2012-04-12 15:07:54

+0

@ user1238850歡迎來到SO。請花2min閱讀:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – 2012-04-12 15:08:49