Thanks. I have the collapse div toggling fine. No problems there.
I just want to be able to collapse it when you click outside the div. That seems to be tricky, the closest I get is the entire window become a toggle button for the collapse
@Pealco. So I tried to add multiple conditions to the if statement, I could have it wrong?. I still have the same problem that the whole window becomes a trigger for toggle for the div.
<script>
window.addEventListener('click', function(e) {
var container = $('#mydiv');
if ((!container.is(e.target)) || (container.hasClass('show')))
{
container.collapse('toggle');
}
});
</script>
I have a menu item that opens a div that is collapsed. The menu item has the usual data attributes…
data-toggle="collapse"
data-target="#myID"
The menu item toggles fine.
I just want the user to be able to click outside the div to re-collapse the div. Which I can get working, the problem I have is when people click anywhere in the window the Div toggles open, even when collapsed.
Hi @PeteSharp, indeed I did. I created a button, toggle visibility “#test”. Created a bloc, added a DIV and inserted a paragraph bric. and called the DIV bric “#test”. I added the script to the page header (and tried the html bric as well), renamed “#mydiv” to “#test”. It keeps responding as a normal toggle. I’m doing something wrong here.