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 Optimize jQuery Code for Better Performance

jQuery is the most popular client side library, in fact almost every ...

article image
»

Using Head.js to Load All Your JavaScript

In the past few years, client side frameworks/libraries have become ...

article image
»

How to Detect Browser Using jQuery

One of the more frustrating parts of creating a new web project is ...

article image
»

Convert Images to Black and White using jQuery

Converting an image to black and white is no longer a manual event. ...

article image
»

How to Use jQuery to Set Textarea Max Length

If you have a textarea field on any of your sites, it might be a good ...

getTable
»

15 Awesome jQuery Table Plugins

Tables are the most preferred way to display data because rows and ...

article image
»

How to Dynamically Open External Links in New Window

Any web developer will probably know that using the ...

article image
»

How to Use jQuery’s .not() Method

jQuery’s .not() method is a method that allows you to return ...

article image
»

jQuery Snippets: How to Add/Remove Classes After Delay

In your projects, there can often be instances of wanting to change ...