I have problem hiding certain popup wich are based on divs. when i click out side those divs they dont hid. Here is the sample code what i m doing..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="../JS/jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#MainCanvas div").blur(function()
{
alert("blured");
});
});
</script>
</head>
<body>
<div id="MainCanvas" style="width: 400px; height: 350px; border: solid 1px black;">
<div class="ui-widget-content" style=" vertical-align:middle; height:60px; border: solid 2px black; width:300px;">
Drag me around
</div>
</div>
</body>
</html>
The blur event occurs when an element loses focus. The blur() method triggers the blur event, or attaches a function to run when a blur event occurs. Tip: This method is often used together with the focus() method.
The blur event fires when focus is lost. By default, a div element cannot have the focus in the first place so it can't be lost. If you set tabindex on a div, then it can gain the focus, but you should almost always be using a more appropriate element (such as a button) when you think about making interactive controls.
Preventing the blur If you want to prevent the blur event from being fired, you have to do so when you are inside the mousedown event, you can do so by invoking the method preventDefault() on the event. Click the checkbox, focus input & then click the button, the textfield never loses focus now.
Definition and UsageThe onblur event occurs when an object loses focus. The onblur event is most often used with form validation code (e.g. when the user leaves a form field). Tip: The onblur event is the opposite of the onfocus event. Tip: The onblur event is similar to the onfocusout event.
for div blur focusout() will work
$('#divCustomerGroup').focusout(function () {
alert('yo');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With