JSFiddle - React, Tailwind, and code Playground
HTML
<a href="" id="lien">
afficher
</a>
<div class="div_flag">
</div>
CSS
html, body {
height: 100%;
}
.div_flag {
width: 100px;
height: 100px;
background-color: red;
}
JavaScript
$(function(){
function showFlags() {
$(".div_flag").show();
}
$('#lien').on('click',function(e){ e.stopPropagation();e.preventDefault();showFlags()})
$('body').not('#lien').click(function() {
if ($(".div_flag").is(":visible")) {
alert("visible");
$(".div_flag").hide()
} else {
alert("visible NON");
showflags();
}
});
})