Tutorial :jquery toggle and multiple links


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 event? 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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »