Jquery更改类

时间:2012-04-12 15:02:21

标签: jquery jquery-ui

我正在尝试更改位于h3内的跨度的类,但我无法做到。以下是我要完成的内容的链接:http://jsfiddle.net/WPxG4/9/

代码:

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>

1 个答案:

答案 0 :(得分:4)

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