Quick Tip – Blur Links With jQuery

Blur Links With jQueryThis quick tip covers a quick usability upgrade for links on AJAX pages. By most browser’s default a dotted line stays around the link after it has been clicked. This becomes a problem with AJAX because the pages are often not reloaded.

Turning it off is simple with jQuery without any impact to the functionality. Give your links some love now and make the appearance smoother for the user later!

The Goal

We are aiming to prevent the following from happening:
Unblurred Link

The jQuery Code

With jQuery loaded in the document, add the following jQuery:

$(document).ready(function(){
	$('.blur').click(function(){
		$(this).blur();
		return false;
	});
});

The Explanation

This snippet of jQuery selects all anchor tags with the class “blur” and monitors for a click event. When a link is clicked the outline is removed (“blurred”).

The return false is optional, it simply prevents a link from loading the target in it’s href attribute. This way the link will only fire the click function. This keeps it from activating a null anchor link of “#” which can make the page jump.

See the results on the live demonstration.

  • Stumble It!
  • Bookmark It!
  • Tweet it!

About Zach Dunn

Zach is a partner and interface designer at One Mighty Roar from Massachusetts, USA. Follow him on Twitter @zachdunn.

 

Discussion

  1. Karl Swedberg

    December 21st, 2008 at 10:17 PM

    Hi Zach. This post reminds me of one I wrote a couple years ago: Quick Tip: Blurring Links. ;)

  2. Zach Dunn

    December 21st, 2008 at 11:59 PM

    @Karl
    I just read over your article and you’re right, they are strikingly similar 8O . In an effort to go over the basics it appears I’ve covered ground you’ve already done quite well. I assure you this was an unintentional coincidence! At the very least I’ve found a new blog to follow!

    Best,
    Zach

  3. Karl Swedberg

    December 23rd, 2008 at 3:00 PM

    Hey Zach, I need no convincing. It’s a common enough issue and an elegant solution, so it’s no surprise at all that more than one person would blog about it. Seems we’ve both found a new blog to follow. Cheers.

  4. STVProductions

    January 19th, 2009 at 3:30 PM

    If it’s about removing the outline of hyperlinks, i suggest you just use CSS and place a{outline:none} in you css file! So if it’s about removing the dotted line, that would be enough!!! Otherwise I have to read this article and the article of Karl again to see what it’s all about ;)

  5. Mick T.

    January 24th, 2009 at 11:01 AM

    The link in the demo doesn’t blur for me on Firefox 3.0.5 (on Ubuntu)?

  6. Zach Dunn

    January 24th, 2009 at 12:21 PM

    @Mick I’m not sure what would be causing that. Does it work for you in other browsers?

  7. Aaron Belafonte

    February 7th, 2009 at 7:11 PM

    I think Mick may be expecting an aesthetic ‘blur’. Not the one discussed here.

  8. Thiago Souza

    February 13th, 2009 at 7:02 PM

    It works. Nice.

  9. Joel Dow

    April 3rd, 2009 at 12:35 PM

    This is not worth the extra js code. Just use a{outline:none;} in your css.

  10. Sam Dunn

    April 3rd, 2009 at 12:41 PM

    @Joel Dow
    The CSS only method is not compatible with all browsers, which is why this bit of code matters. If this doesn’t matter to you then your method is certainly functional.

Join the Conversation!

Remember: Life's not all doom and gloom, so please keep it constructive. If we've made an error or missed something big, please let us know! Learning is revisions, after all.

CommentLuv is Enabled

 

Sponsors

Advertise on Build Internet!