4
I have a div
with a botão
inside to close it. At first, she’s with display: none
, but to the click on on one button on another div
, she turns into display: block
.
I need to find a way to when she is display: block
, and if by incident click on in anything other than div
(or inside the div), then, a click
is triggered on the button that the closeness.
I tried following code:
$(document).on('click', function(e) {
alert($("div.peca").css("display")); //retorna none
if ( $("div.peca").css("display") === "block" ) {
alert($("div.peca").css("display")); //retorna block
$("div.peca button.fechaPeca").trigger("click");
}
});
But when I click on the button that makes it display: block
, Already comes that she is display: block
and then ends up closing automatic.
What to do in this case?
I know that the error is in this line:
$("div.peca button.fechaPeca").trigger("click");
'Cause I mentioned it and I put one alert
in place and worked.
I also tried to:
$("div.peca button.fechaPeca").click();
Same thing.
But no idea why this error is occurring. That is, the botões
stop accepting click
Another text I wrote was
$(".fechaPeca").on("click", function() {
$("div.pecaGas").css("display","block");
$("div.peca").css("display","none");
})
replaced by
$(".fechaPeca").on("click", function() {
alert();
})
The alert()
worked.
But,
$("div.pecaGas").css("display","block");
$("div.peca").css("display","none");
It doesn’t work when I access
$(".fechaPeca").on("click"
Through another click
I guess I didn’t quite understand!
– Carlos Rocha
@Carlosrocha jumps here https://chat.stackexchange.com/rooms/68278/doubts-selectes to avoid more comments here that are hard to follow
– Sergio