Code has been added to clipboard!

jQuery .focusOut(): Add Event Handlers to the focusOut Event

Reading time 1 min
Published Jul 3, 2019
Updated Sep 30, 2019

jQuery focusOut: Main Tips

  • The jQuery .focusOut() is a shorthand for .on() with focusOut as the event parameter.
  • This method binds an event handler to a focusOut event, invoked when the specified element or its children in jQuery lose focus.
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid certificates of completion
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

Usage of .focusOut()

A jQuery focusOut event fires when an element or its descendants in jQuery lose focus. The .focusOut() method adds an event handler to the focusOut event.

In the example below, you will see no changes as you select an input field. However, when you click somewhere else, the field loses focus and changes its color:

To specify a function to be run when the specified element or its children lose focus, use this syntax:

$("selector").focusout(function)

.focusOut() vs. .blur()

Beginners sometimes confuse jQuery focusOut and blur events, since both of them fire when an element in jQuery loses focus.

If the element has no descendants, there is actually no difference between the two events. However, if there are children elements and they lose focus, the focusOut event will fire, and blur will not.

Note: if you don't specify any parameters, the method will simply trigger the event.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 28/01/2021
3176 People Used
Only 97 Left
Rating
5.0