2012-04-12 28 views
2

h3内にあるスパンのクラスを変更しようとしていますが、できません。ここで私が達成しようとしています何へのリンクです:http://jsfiddle.net/WPxG4/9/Jquery change class

コード:

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

+0

@ user1238850あなたの歓迎^ _ ^受け入れられた回答をここで選択することを忘れないでください。 – Neal

+0

@ user1238850ようこそ。これを読むには2分かかります:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –