Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
215,939 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.