javascript - jQuery how to make slideToggle applies one each item -


how can make toggle fadein fadeout applies on each itemsblock? when click anyone, applies of them. please ? thanks

online sample

     <div class="items">         <div class="warp">             <span class="change">tester</span>              <span class="click">expand</span>         </div>         <div class="invisible">             <div class="red"> red </div>             <div class="black"> black </div>         </div>     </div>     <div class="items">         <div class="warp">             <span class="change">tester</span>              <span class="click">expand</span>         </div>         <div class="invisible">             <div class="red"> red </div>             <div class="black"> black </div>         </div>     </div> 

jquery

 $('.invisible').hide();  $('.warp').addclass('bg');  $(".warp").click(function () {         $(".invisible").slidetoggle("slow", function () {             if ($(this).is(':visible')) {                 $('.warp').removeclass('bg');             }else{                $('span.click').css('visibility', 'visible');                 $('.warp').addclass('bg');             }          });      $('span.click').css('visibility', 'hidden');         }); 

how can make toggle fadein fadeout applies on each itemsblock? when click anyone, applies of them.

this because use $(".invisible") selects elements class invisible. have find element related toggle element(your .warp element), in case this: $warp.next(".invisible").

see updated fiddle.

updated jquery code:

$(".warp").click(function () {     var $warp = $(this);      $warp.next(".invisible").slidetoggle("slow", function () {         if ($(this).is(':visible')) {             $warp.removeclass('bg');         }else{                         $warp.find('span.click').css('visibility', 'visible');               $warp.addclass('bg');         }     });      $warp.find('span.click').css('visibility', 'hidden');       }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -