How Do I Hide A Div When It Loses Its Focus?
Basically I am trying to implement a login such as that of the new twitter. When you click on Sign In a div pops up with the fields. Now when I click anywhere outside the div (div
Solution 1:
If moving your mouse outside is not enough and you want it to disappear only if the user clicks outside of it, here's a snippet that might help you.
$('body').click(function(evt) {
if($(evt.target).parents('#loginDialog').length==0) {
$('#loginDialog').hide();
}
});
Solution 2:
Better to use jquery fancybox plugin for iframe http://fancybox.net/ in the various example
[UPDATE]::Sorry for stupid hypothetical code. check the working code
<scripttype="text/javascript">
$(function (){
$(document).click(
function (e){
var blur = $('#blur');
var position = $(blur).position();
var height = $(blur).height();
var width = $(blur).width();
if((e.clientX > position.left && e.clientX < position.left + width) &&
(e.clientY > position.top && e.clientY < position.left + height)
){
alert(e.clientX+' '+e.clientY);
}
else{
/*Hide the div*/
$('#blur').hide();
/*Hide the div*/
}
}
)
})
</script><divid="blur">Blur me</div>
Solution 3:
Not such a good practce but might work...
$('body').click(function(){
$('#loginDialog').hide();
});
$('#loginDialog').click(function(evt){
evt.stopPropagation();
});
Post a Comment for "How Do I Hide A Div When It Loses Its Focus?"