Is there a way to modify a script so that it closes the menu when clicking on any part of the screen, not just on an 'li' element?
$(function() {
$('.drop-down-input').click(function() {
$('.drop-down-input.selected').removeClass('selected'); // Clear previous selection
$(this).addClass('selected');
$(this).find(".dropdown-list").show();
});
$(document).on("click", ".drop-down-input.selected li",
function(e) {
e.stopPropagation();
$('.drop-down-input.selected .dropdown-list').hide().siblings().val($(this).html());
});
});
This is my HTML code:
<div class="styled-input-container drop-down-input">
<input id="simple_2" class="drop-down-select" placeholder="input text" type="text">
<ul class="dropdown-list">
<li>eeee</li>
<li>xxxx</li>
<li>xxxx</li>
<li>xsssxxx</li>
</ul>
</div>