jquery - using not function with $this and is(":visible") -


i have following html...

<button>one</button> <div class="div1"></div> <button>two</button> <div class="div2"></div> <button>three</button> <div class="div3"></div> <button>four</button> <div class="div4"></div> 

and jquery have used....

$(document).ready(function(){   $("button").click(function(){     $(this).next().slidetoggle();   }); }); 

i use slidetoggle() function (that hide) again if others open(visible). how use not function $this , is(":visible") while other visible clicked adjacent div shown , others closed?

http://jsfiddle.net/vwfv7/

like this?

$(document).ready(function(){   $("button").click(function(){      $(this).next().slidetoggle().siblings('[class^=div]').slideup();   }); }); 

demo

you dont need use :visible slideup. slide siblings div particular class pattern.

or since want use :visible , not:

$(document).ready(function(){   $("button").click(function(){       $('[class^=div]:visible').not($(this).next().slidetoggle()).slideup();       //select class pattern visible slideup (provide container possibly)       //but exclude clicked element's next div , slidetoggle simultaneously.   }); }); 

demo


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -