手风琴在点击元素中更改类,简单方法吗?

时间:2013-09-08 16:56:37

标签: jquery html jquery-ui-accordion

HTML

<div class="accordion">
  <div class="accord-header">
    <a class="fleft">1 Title</a>
    <a class="fright exp"></a>
  </div>
    <div class="accord-content">
     ble ble ble
    </div>
  <div class="accord-header">
    <a class="fleft">2 Title</a>
    <a class="fright exp"></a>
  </div>
    <div class="accord-content">
     bla bla bla
    </div>
</div>

的jQuery

$(document).ready(function() {

    $(".accordion .accord-header").click(function() {
      if($(this).next("div").is(":visible")){
      $(this).next("div").slideUp("slow");
      } else {
        $(".accordion .accord-content").slideUp("slow");
        $(this).next("div").slideToggle("slow");
      }
    });
});

基本上,它做什么,它是我的文章列表的手风琴。现在我需要在单击1个选项卡时将<a>元素“fright exp”的类更改为“fright imp”,对于下一个选项卡则相同。 “惊吓exp”是符号+和“惊吓imp”是 - ,有一种简单的方法吗?

1 个答案:

答案 0 :(得分:0)

$(document).ready(function() {

    $(".accordion .accord-header").click(function() {

      if($(this).next("div").is(":visible")){
        $(this).next("div").slideUp("slow");
        //clas that you want to add
        $(this).find('a').eq(1).addClass('yourclass');
        //clas that you want to remove..if any
        $(this).find('a').eq(1).removeClass('yourclass');
      } else {
        $(".accordion .accord-content").slideUp("slow");
        $(this).next("div").slideToggle("slow");
      }
    });
});