jQuery如何在toggle上更改父div的类

| 当我滑动我拥有的简单手风琴时,我想更改链接元素的类和.revealBox div,它根据手风琴是打开还是关闭来包装整个手风琴 我的jQuery是
$(document).ready(function() {
    // choose text for the show/hide link - can contain HTML (e.g. an image)
    var showText = \'Hide Information\';
    var hideText = \'Show Information\';
    var is_visible = false;
    $(\'.collapseLink\').append(\'<span class=\"dottedBot\">\' + showText + \'</span>\');
    $(\'.revealBoxContents\').show();
    $(\'a.collapseLink\').click(function() {
        // switch visibility
        is_visible = !is_visible;
        // change the link depending on whether the element is shown or hidden
        $(this).html((!is_visible) ? showText : hideText);
        // toggle the display - uncomment the next line for a basic \"accordion\" style
        //$(\'.toggle\').hide();$(\'a.toggleLink\').html(showText);
        $(this).parent().next(\'.revealBoxContents\').slideToggle(\'slow\');
        // return false so any link destination is not followed
        return false;
    });
    // toggle the bottom link
    $(\'.collapseLink\').click(function() {
        $(this).parents(\'.revealBoxContents\').stop(true, true).slideToggle(\'slow\');
        $(\".collapseLink\").html((!is_visible) ? showText : hideText);
        $(this).parent(\'.item\').toggleClass(\'current\');

    });
});
我的网址是 http://satbulsara.com/NSJ-local/eqs1.htm 谢谢, 周六     
已邀请:
您要在元素上使用addClass()函数。 http://api.jquery.com/addClass/ 您还可以使用jQuery文档中所示的toggleClass()来做到这一点:
$(\'div.foo\').toggleClass(function() {
      if ($(this).parent().is(\'.bar\')) {
        return \'happy\';
      } else {
        return \'sad\';
      }
});
http://api.jquery.com/toggleClass/     
您可以利用jquery \的addClass()和removeClass()添加和删除类。     

要回复问题请先登录注册