I do not know why another condition does not work, I tried several methods.
if($('hiddendDiv').attr('style') === 'display:none') {
$('buttonDiv').click(function() {
$('hiddendDiv').attr('style',"display:block");
});
} else {
$('body').click(function(){
$('hiddendDiv').attr('style',"display:none");
});
}
hiddendDiv It has style="display:none"
When I click the button buttonDiv, it hiddenDivreceives display: block, and after that, when I click anywhere on the page (to close hiddenDiv), it hiddenDivdoes not receive display: none.
I am trying to create <div>one that opens when I click the button, and closes when I click anywhere on the page.
source
share