I am styling a few MultiSelect elements with unordered (<ul>
) HTML lists and this function is meant to hide the element when a user clicks anywhere on the document other than 'dropdown_box' or 'dropdown_container'.
The function isn't working for anything within the <ul>
tags, and it's hiding the element as soon as soon as a list item is clicked. I've tried specifying both the id of the <div>
as well as the <ul>
and it still closes as soon as it's clicked.
UPDATE - I created a jsfiddle to demonstrate the problem http://jsfiddle.net/chayacooper/ezxSF/16/
There is a separate mouseleave function which closes the element for most uses, but I need to add this functionality in order to close the element if the user clicks to open it but doesn't mouse over any of the 'UL Element' items.
JS
$('html').click(function (e) {
if (e.target.id == 'dropdown_box' || e.target.id == 'dropdown_container') {
$("#select_colors").show();
} else {
$("#select_colors").hide();
}
});
HTML
<div id="dropdown_box">Select</div>
<div id="dropdown_container">
<ul id="select_colors">
<!-- Several List Item Elements -->
</ul>
</div>