2012-04-12 70 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