xanka xanka - 2 months ago 7
CSS Question

how do toggleClass in jquery?

I has example code html

<div class="new">
<div class="wrapper">
<div class="icon"></div>
<div class="content">content</div>
</div>
<div class="list"></div>
<div class="wrapper">
<div class="icon"></div>
<div class="content">content</div>
</div>
<div class="list"></div>
</div>


updated: I want when click to class icon in wrapper first toggle class list first . And class list second not change. Many thanks

Answer

$('.icon').click(function(){
$(this).next('.content').toggle('slow')



})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="new">
    <div class="wrapper">
          <div class="icon">QWE</div>
          <div class="content">content</div>
    </div>
    <div class="wrapper">
          <div class="icon">QWE</div>
          <div class="content">content</div>
    </div>
</div>

Use .next()

Description: Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector.

Or .siblings()

Description: Get the siblings of each element in the set of matched elements, optionally filtered by a selector.

Comments