Clicking on a certain div triggers a popover to display another div, which works initially. However, once the popover is removed by clicking outside the div, it requires two clicks to trigger the popover again. How can this be fixed so that it always works with just one click? Any assistance would be greatly appreciated. Thank you in advance.
Update:
An attempt was made to solve this issue but it did not work as expected. The proposed solution only partially worked on Bootstrap 4 and did not work at all on Bootstrap 5. Here is the attempted solution:
$('body').on('hidden.bs.popover', function (e) {
$(e.target).data("bs.popover")._activeTrigger.click = true
});
$(function() {
$(".testDiv").popover({
container: 'body',
html: true,
placement: 'bottom',
sanitize: false,
content: function() {
$('.testDivCon').show()
$('.wifiInfoContent').append('<button class="testButton">Click Me</button>')
return $('.wifiInfoContent').html();
}
});
});
$('.testDivCon').on('click', function() {
$('.popover').remove()
$('.testDivCon').hide()
})
$(document).on('click', '.testButton', function() {
console.log('clicked')
})
.testDivCon {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: green;
}
.testDiv {
position: absolute;
top: 10%;
left: 20%;
width: 20%;
height: 15%;
background-color: black;
}
.wifiInfoContent {
display: none;
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceaca1a1babdbabcafbe8efbe0ffe0fd">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72101d1d06010600130232475c435c41">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01636e6e75727573607141342f302f32">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="testDivCon"></div>
<div class="testDiv"></div>
<div class="wifiInfoContent"></div>