I have some divs (title
). When I press, lets say div1
, the subtitle shows. And when I press another div, lets say div2
, then div1
hides, and div2
are being showed.
What I want, is when I press div1
, and then press div1
again, it hides.
You can see in the if/else statement what I've tried.
Hope someone can help me here.
$(document).ready(function()
{
$(".title").click(function()
{
var $element = $(this);
$(".open").removeClass("open");
$('.subtitle').hide(500);
$element.toggleClass('open');
$element.children('.subtitle').toggle(500);
if($(this).hasClass() == "open")
{
$element.children(".subtitle").hide(500);
}
});
});