Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

jQuery slideDown only section that has been clicked

I am using jQuery to reveal some content on click like this...

$(document).ready(function () {

    $('.extraClick').click(function(){

          $( ".extra" ).slideDown( "slow", function() {});

    });

});
.extra {
    display: none;
}

.section {
    padding:10px;
    background:grey;
    margin-bottom:10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="section">

    <div class="container">
    
      <p>
          This is the section 1 content
      </p>
      
      <div class="extraClick">
          Click Me
      </div>

    </div>
    
    <div class="extra">
         This is some extra content
    </div>

</div>

<div class="section">

    <div class="container">
    
      <p>
          This is the section 2 content
      </p>
      
      <div class="extraClick">
          Click Me
      </div>

    </div>
    
    <div class="extra">
         This is some extra content
    </div>

</div>

<div class="section">

    <div class="container">
    
      <p>
          This is the section 3 content
      </p>
      
      <div class="extraClick">
          Click Me
      </div>

    </div>
    
    <div class="extra">
         This is some extra content
    </div>

</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you have to use $(this) instead of $(".extra").


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...