I’m using this form select with image options https://codepen.io/antonandoff/pen/PmQvBz
My issue is, the dropdown only closes if you select an option within the dropdown, and not if you click outside anywhere on the page as a traditional <select>
would.
I’m guessing I need some jQuery to do this, but this code below won’t open the dropdown. I’m also guessing I have something wrong with the :not()
selector
jQuery(document).on('click', 'div:not(".vodiapicker")', function(e) {
$(".b").hide();
});
3
Answers
You need to add a "global" click handler to hide the dropdown:
Combine this with
return false
in the dropdownshow code so that showing the drop down doesn’t immediately hide it:Updated code:
You can achieve this in several ways, here is one example how to do this.
Since you’re creating a div as "select dropdown" you need to check if the click is not
btn-select
norb
This code may not work on Codepen.
When you copy the code from Codepen to html, the code will work properly.