I have this function:
$('input#auto_results').bind('blur', function(e) {
$('.result').bind('click', function() {
return;
});
$('#results_container').hide();
});
Basically, I would like the #results_container to hide on blur UNLESS an element with the class .result is clicked.
The above function does not work
Problem with your code:
What you’re trying to do, is attaching a
clickevent handler on.resultin the event handler of another event (blur).Your code will do nothing except attaching this
clickhandler that basically does nothing.Simple option:
The
blurevent will be triggered first, and theclickon.resultssecond, so this is not an easy situation.The simplest way you can do this is:
jsFiddle Demo
So just hiding the container, an on click, show it again. Results in a small blink.
Timeout option:
Another option I can think of, is setting a small timeout when the
bluris triggered, and on the click event of.results, cancel it. In this example, I store the timeout onbodywith the.data()function, you could store it on a more logical element, this is just a demonstration:jsFiddle Demo