sasidhar sasidhar - 1 year ago 85
jQuery Question

Focus out event not working as expected in jquery

Here is the JavaScript I am using:

<script type="text/javascript">

var left_pos= document.getElementById('login_button').offsetLeft;
var top_pos= document.getElementById('login_button').offsetTop+5;

here is the html i am using.

<a id="login_button">login</a>
<div id="login_box_pane" >
Username: <input type="text"/>
Password:<input type="password"/>

Here is the CSS I am using:


The functionality I want is, whenever the "login" is clicked then there should appear a small box just below that asks for username and other details and it should disappear when ever the "login" is clicked again or anywhere else on the page, that is a focus out.... but it isn't working that way. I even tried mouseout and other events but tough luck. What's wrong with the code?

Is there any other way of achieving this?

Answer Source
$(document).click(function(e) {
  if(($('id') == 'login_button')){
  else if(!($('#login_box_pane').length>0)){

This seems to address my problem correctly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download