Im using the following to open/close a div
$(".alerts").click(function(){
$(this).toggleClass("active").next().slideToggle(50);
But I want a certain function to trigger only if the box was closed and is being opened, how can I determine this? I prefer not to use cookies or anything like that
thanks!
You can use the
visibleselector with theismethod like this –An example on jsfiddle.
The –
portion is checking to see if the next element of
thisis visible or not. If it is, then it returns true. As a result, thealertmethod gets executed.Here is the documentation for the
visibleselector and here is the documentation for theis()method.