0
I would like to remove the "active" class from "liToggle" in case you closed a Slidetoggle.
I tried to use is(':hidden')
but unsuccessfully. If I put right after the open parole, it closes at the same time. I am without ideas for logic.
Can someone help me?
$("aside #menu-busca ul > li a").click(function(){
if($(this).attr('href') == "#"){
var ulToggle = $(this).parent().children("ul");
var liToggle = $(this).parent();
ulToggle.slideToggle("slow");
// * Se estiver aberto
if (ulToggle.is(":visible")){
$(liToggle).addClass("ativo");
}
return false;
}
});
ulToggle
is a collection of several elements right? which one do you want to know if it is visible? Puts a jsFiddle that makes it easier to understand the problem.– Sergio
Checks if the css display value is block.
– Antonio Alexandre
@Sergio, Segue! http://codepen.io/maykelesser/pen/RKdgvY... I want to know if the clicked li is visible or not.
– Maykel Esser
@MaykelEsser http://codepen.io/sergiocrisostomo/pen/vgPJgb
– Sergio
@Sergio saw that you put a console.log to check if it’s open or closed, but see that if I close, it returns 2 booleans (true and true). If it is no longer Visible, why is it returning TRUE yet?
– Maykel Esser
@Maykelesser http://codepen.io/sergiocrisostomo/pen/wgOrWd had 2 console.log in that code. I had moved to the first line because then you know for sure that slideToggle hasn’t started yet. However, it may still be running a slide toggle, so it would be better to have a flag. What do you want to do in the source after knowing if it is open and/or closed?
– Sergio
@Sergio When Slidetoggle is open, add an "active" class to the clicked LI. This I have already done. When closing, I would like it removed. I tried with ELSE, is(":Hidden"), but without success.
– Maykel Esser