I want to hide a div on focusout of its child elements.say,
lets have username and password field in a div,it will be minimized initially, user will clicks opens the div then if user click anywhere outside the div should close the mydiv
<body>
<div id="mydiv" onblur="alert('hi');" tabindex="1" style="border: 1px solid black;">click off me to activate onblur
<br/>
username: <input type="text" name="username" onblur="alert('hi');" tabindex="1" />
<br/>
Password: <input type="text" name="password" />
</div>
</body>
(see the JS fiddle : http://jsfiddle.net/vC7Rb/1/)
I tried putting onblur for both div as well as text field but that require common function call from which I need to check if any of the element is still have focus and then only hide the div.thats seems too much, so is there any simple way to do this.
I want implement this in pure javascript code and it should be compatible in all browser(IE,firefox,chrome).