Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I blur everything by focusing on the document?

Tags:

using Jquery/javascript

Is it: $(document).focus()?

like image 697
TIMEX Avatar asked Apr 02 '10 20:04

TIMEX


People also ask

What is focus blur?

Events focus/blur The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an input field. In the example below: The blur handler checks if the field has an email entered, and if not – shows an error.

What is blur () method?

blur() method removes keyboard focus from the current element.

What is blur input?

The blur event fires when an element has lost focus. The main difference between this event and focusout is that focusout bubbles while blur does not. The opposite of blur is focus . This event is not cancelable and does not bubble.

How do you Unfocus an element in JavaScript?

Use the blur() method to remove the focus from an element, e.g. input. blur() . If you need to remove the focus from the currently active element without selecting it, call the blur method on the activeElement property - document.


1 Answers

The .focus() method on a jQuery-wrapped element will bind to the onfocus event if a function is passed as the first parameter, or trigger attached event handlers with no parameter.

I'm not sure why you're trying to do what you're trying to do, but if you're trying to blur the currently active element, no matter what element it is, you can use:

if ("activeElement" in document)     document.activeElement.blur(); 

This isn't advised though, as doing so will reset the tabbing order and potentially annoy keyboard-navigating users.

like image 123
Andy E Avatar answered Oct 04 '22 05:10

Andy E