0

我想根据我点击的“abtn”切换我的课程“acontent”中的内容。

我的HTML:

<div class="accordion">
  <div class="abtn">
    <input id="A-1" type="radio" value="A">
    <label class="chars" for="A-1">A</label>
    <div class="char-more">Learn More</div>
 </div>
<div class="acontent">Hello I am content A</div>

 <div class="abtn">
     <input id="B-1" type="radio" value="B">
     <label class="chars" for="B-1">B</label>
     <div class="char-more">Learn More</div>
 </div>
 <div class="acontent">Hello I am content B</div>

 <div class="abtn">
     <input id="C-1" type="radio" value="C">
     <label class="chars" for="C-1">C</label>
     <div class="char-more">Learn More</div>
   </div>
     <div class="acontent">Hello I am content C</div>
  </div>

jQuery:

  $(".abtn .char-more").click(function(){
      $(this).parent.next(".acontent").slideToggle("fast")
      .siblings(".acontent:visible").slideUp("fast");
      $(this).toggleClass("active");
      $(this).siblings(".char-more").removeClass("active");
  });

JSFIDDLE:http: //jsfiddle.net/zRqYM/30/

4

1 回答 1

0

缺少级的( ) .. 应该是.parent()

您也可以尝试使用.closest()

$(this).closest('.abtn').nextAll(".acontent").first().slideToggle("fast")
于 2012-11-01T21:58:46.953 回答