Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why does the JQuery "blur" event listener not work as expected?

I have a mobile nav - I'm trying to write something that will take you straight to the "close" button, so that the user can can close the mobile nav. I'm trying to trigger this when the last item in the menu loses focus. (when using your keyboard to tab through the menu)

However, what is happening right now - as soon as that last item receives focus, it jumps straight to the close button. So you don't even get a chance to click the link

Why is this happening?

    $('.closeNav + ul a[href="#lastLink"]').blur(function() {
        $('.closeNav').focus();
    });

1 Answer

Steven Parker
Steven Parker
229,695 Points

This code seems to work as intended with my Chrome browser. But then I had to make up some HTML to go with it. Perhaps the issue is in the HTML.

Please show the actual HTML code this is used with.