I am currently working on creating a dropdown suggestion box that hides when the input field and dropdown box are no longer in focus.
My HTML code:
<input type="text" id="user_address">
<div id="user_address_sg">SUGGESTION</div>
<div id="another element">Pressing another element on the page should hide the suggestion box</div>
I have attempted the following:
$('[id=user_address][id=user_address_sg]').focusout(function (){
$('#user_address_sg').hide();
});
Why isn't the user_address_sg
hiding when I select another input field or other elements on the page?
Images (1st: When typing a name, 2nd: Selecting another form while suggestions appear)
First image: The suggestion box should be displayed and clickable
https://i.sstatic.net/UwlFh.png
Second image: The suggestion box should disappear upon doing this