I have a div
with a botão
inside to close it . At first it is display: none
, but clicking on a button in another div
, it becomes display: block
.
I need to find a way for when it is display: block
, and if by clicking on something other than div
( or within div ), then a click
is triggered on the date button.
I tried the 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
, it already comes that it is display: block
and then it finishes closing automatic.
What to do in this case?
I know the error is on this line :
$("div.peca button.fechaPeca").trigger("click");
Well I commented on it and put a alert
in place and it worked.
I've also tried:
$("div.peca button.fechaPeca").click();
Same thing.
But no idea why this error is occurring. That is, botões
stops accepting click
Another text I made was
$(".fechaPeca").on("click", function() {
$("div.pecaGas").css("display","block");
$("div.peca").css("display","none");
})
replace with
$(".fechaPeca").on("click", function() {
alert();
})
alert()
worked.
But,
$("div.pecaGas").css("display","block");
$("div.peca").css("display","none");
Does not work when accessing the
$(".fechaPeca").on("click"
Through another click