Is there a jQuery unfocus method?

JavascriptJquery

Javascript Problem Overview


How can I unfocus a textarea or input? I couldn't find a $('#my-textarea').unfocus(); method?

Javascript Solutions


Solution 1 - Javascript

$('#textarea').blur()

Documentation at: http://api.jquery.com/blur/

Solution 2 - Javascript

Based on your question, I believe the answer is how to trigger a blur, not just (or even) set the event:

 $('#textArea').trigger('blur');

Solution 3 - Javascript

Guess you are looking for .focusout()

Solution 4 - Javascript

I like the following approach as it works for all situations:

$(':focus').blur();

Solution 5 - Javascript

This works for me:

// Document click blurer
$(document).on('mousedown', '*:not(input,textarea)', function() {
	try {
		var $a = $(document.activeElement).prop("disabled", true);
		setTimeout(function() {
			$a.prop("disabled", false);
		});
	} catch (ex) {}
});

Solution 6 - Javascript

So you can do this

$('#textarea').attr('enable',false)

try it and give feedback

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlec SmartView Question on Stackoverflow
Solution 1 - JavascriptRichieHindleView Answer on Stackoverflow
Solution 2 - JavascriptsonjzView Answer on Stackoverflow
Solution 3 - JavascriptAdam BoostaniView Answer on Stackoverflow
Solution 4 - JavascriptJavidView Answer on Stackoverflow
Solution 5 - Javascriptd'Artagnan Evergreen BarbosaView Answer on Stackoverflow
Solution 6 - JavascriptlolView Answer on Stackoverflow