开发者

jquery toggle and multiple links

开发者 https://www.devze.com 2023-01-04 16:10 出处:网络
i\'m using jquery toggle to show/hide a div on different links. It shows/hides them fine, however if you click on one of the other links before closing the first link toggle, the first div is still sh

i'm using jquery toggle to show/hide a div on different links. It shows/hides them fine, however if you click on one of the other links before closing the first link toggle, the first div is still shown.

Is there any way of checking if there are any other open toggle events open, if so, close them and then continue with the new toggle ev开发者_开发百科ent? If that makes sense?

My code is:

$("#icons ul li a").toggle(function(){
  $(this).addClass("active");
  $("#newdiv").show();
}, function() {
  $(this).removeClass("active");
  $("#newdiv").hide();
});


You can use the :visible selector along with the divs you are toggling.

$('.mydiv:visible').hide();
0

精彩评论

暂无评论...
验证码 换一张
取 消