1
I created a tab that opens and closes using jQuery and am having some problems closing it:
HTML
<div id="aba" style="position: absolute">
<img src="#"/>
<span id="fechar">X</span>
</div>
jQuery
var fechado = true;
$("#aba").click(function(){
if (fechado){
$("#aba").animate({left: "10px"});
fechado = false;
}
});
$("#fechar").click(function(){
if (fechado == false){
$("#aba").animate({left: "0px"});
fechado = true;
}
});
What happens is that when I click on the close, it probably understands that it is clicking on the open as well; that is, it closes and opens right away. I tried to use a flag, but without success.
The real problem is that I can’t take the close button out from inside the tab.
I think the error is in not changing the value of the variable
fechado
, try to add below the$("#aba").animate({left: "10px"});
onefechado = false
– Hermes Autran
Since the span is below the DIV, possibly it is superimposed by it, that is, you think you are clicking on the span but you are clicking on the DIV. Try to change the location or use z-index.
– Ascension
@Hermesautran, my fault, I forgot to put in the code, but there is.
– ptkato
@Ascension, it didn’t work.
– ptkato
Another thing, you shouldn’t take the
animate
of$("#aba")
instead of$("#fechar")
. Like thespan
is inside thediv
, if you hide it all will hide too. Try$("#aba").animate({left: "0px"});
instead of$("#fechar").animate({left: "0px"});
– Hermes Autran
Again, it’s like closing the tab, I misspelled.
– ptkato