top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the use of blur function in JavaScript?

+2 votes
469 views
What is the use of blur function in JavaScript?
posted Aug 7, 2017 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The 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.

The blur method has no effect on an element that is not the active element in the document. If you use the blur method for the active element, then it loses the active state (and of course the focus, too), and fires the onblur event. Note: the onbeforedeactivate, ondeactivate, onfocusout and DOMFocusOut events are also fired. In that case, the body element becomes the active element.

You do not need to call the blur method on the active element before you set the focus to another element, only use the focus or setActive method on that element.

The blur method behaves differently on the window object in different browsers.

If the browser window is the foreground window and the window.blur method is called:
in Internet Explorer, the operating system activates another application window
in Firefox, Google Chrome and Safari, the browser window only loses the active state when another Firefox, Google Chrome or Safari application can be activated
in Opera, the blur method has no effect for windows.

If you need the active element in the document, use the activeElement property. If you need to simulate other events, see the pages for the dispatchEvent and fireEvent methods.

Syntax:

object.blur ();

Example:

document.getElementById('myField').onblur();
answer Aug 7, 2017 by Manikandan J
...