(function( $ ) { $('.search-submit').on('keydown', function (e) { if ($('#menu-toggle').css('display') == 'flex' ) { if ($("this:focus") && (e.which == 9) && (! e.shiftKey)) { $('#menu-toggle').focus(); e.preventDefault(); } } }); })( jQuery );