X

LATEST #JQUERY NEWS

How to Use jQuery’s .blur() Method


jQuery’s .blur() method isn’t exactly what it sounds like — the word “blur” in this context should be taken as more of a figurative term than a literal one. The .blur() method doesn’t actually apply a blur effect to any elements, it simply refers to when an element was in focus and then becomes out of focus. So if a text input element was in focus for example, perhaps because a user was writing in it or filling it out, and then they click anywhere outside of that input, it becomes out of focus. When this happens, you can use the .blur() method to trigger an action or an event.

Your HTML may look something like this:

Enter your email address: <input type=”text” class=”email”>

Now let’s say you want that element to fade away when it becomes out of focus, here’s the jQuery code you could use for that:

$(“.email”).blur(function(){
$(this).fadeOut();
})

.fadeOut is only one of dozens of options that can be used in this scenario. Other popular methods to use when an item becomes out of focus are alert(), .toggle(), or .hide().

Recently Published

article image
»

How to Use Google Analytics with jQuery Mobile

jQuery Mobile is an HTML5 based web-page framework that’s ...

article image
»

jQuery Snippets: Using jQuery to Check All Boxes

When you’ve given your users a ton of checkbox input fields ...

article image
»

Useful jQuery Code Snippets for Working with Images

Images are an essential part of any website and sometimes working ...

article image
»

How to Use jQuery to Check if Cookies are Enabled

A cookie (not the kind with chocolate chips) is a small piece of data ...

article image
»

A Beginner’s Guide to jQuery’s Selectors

We talk a lot about event methods on this site, but not so much about ...

article image
»

Add Keyboard Shortcut to Anchor Tag Using jQuery

Making a user friendly website can be quite a challenging task. There ...

Screen Shot 2017-04-23 at 10.15.41 AM
»

How to Use jQuery to Create a Sticky Navigation on Scroll

Creating “sticky” elements is something that can often be ...

article image
»

How to Use jQuery’s Keystroke Methods

jQuery has a few built-in keystroke methods that are all triggered by ...

article image
»

How to Change iFrame Styling Using jQuery

If you’ve ever had the displeasure of working with iFrames, ...