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
»

jQuery’s .children() Method

Just like in CSS, it’s possible to use jQuery to select the ...

article image
»

jQuery’s .click() Method

With jQuery, it’s super easy to make something happen as a result ...

article image
»

Using jQuery’s .resize() Method

jQuery’s .resize() method is a cool way to have an event ...

article image
»

How to Use jQuery to Search and Replace HTML

Have you ever made a mistake in your code or in your text and dreaded ...

article image
»

How to Use jQuery’s .mouseover() Method

jQuery’s .mouseover() method is used to execute some jQuery ...

article image
»

How to Use jQuery’s .blur() Method

jQuery’s .blur() method isn’t exactly what it sounds like ...

article image
»

jQuery 3.0: Fix url.indexOf is Not a Function Error

jQuery 3.0 is out, and if you started working with it and plan to ...

article image
»

Set/Get/Delete Cookies with jQuery

There are a lot of plugins you can use to set, get, and delete ...

Screen Shot 2016-11-26 at 12.05.09 PM
»

3 Best jQuery Video Gallery Plugins

Do you have a lot of videos that you’d like to embed or neatly ...