views:

11514

answers:

5

Hello,

I'm trying to show up a container if a input field gets the focus and - that's the actual problem - hide the container if focus is lost. Is there an opposite event for jQuery's focus?

Some example code:

<input type="text" value="" name="filter" id="filter"/>

<div id="options">some cool options</div>

<script type="text/javascript">
  $('#options').hide();

  $('#filter').focus(function() {
    $('#options').appear();
  });
</script>

And what I'd like to do is something like this:

$('#filter').focus_lost(function() {
  $('#options').hide();
});
+42  A: 

Use blur event to call your function when element loses focus :

$('#filter').blur(function() {
  $('#options').hide();
});
Canavar
works perfectly, thanks!
Joe
+12  A: 

Use "blur": http://docs.jquery.com/Events/blur#fn

NVRAM
Thanks to you, too! ;)
Joe
A: 

Thank you! Simple but very helpful to me!

Dave

Dave
A: 

oh, this is very simple. thanks everyone for help me out... :)

Naseer Ahmad
A: 

man... stackoverflow is the best place ever for any questions regarding programming. gotta answer more.