Skip to main content

Bug Tracker

Side navigation

#1440 closed bug (fixed)

Opened July 30, 2007 05:07PM UTC

Closed July 31, 2007 02:23AM UTC

Last modified May 21, 2013 01:41PM UTC

.focus() doesn't fire for 'a' (anchor) element

Reported by: rworth Owned by: john
Priority: major Milestone: 1.1.4
Component: event Version: 1.1.3
Keywords: focus event anchor Cc:
Blocked by: Blocking:
Description

This is a regression from 1.1.2 to 1.1.3.x:

<a id="myLink">This should be focused.</a>

<script type="text/javascript">

$(function() {

$("#myLink").focus();

});

</script>

Expected:

The link receives focus, visible by an outline

Actual:

The link does not receive the focus

Cause:

I've traced this to the trigger: function

jQuery\\event\\event.js (r1765, line 132)

-if ( fn && val !== false )

+if ( fn && val !== false && !jQuery.nodeName(element, 'a') )

Attachments (0)
Change History (7)

Changed July 31, 2007 01:52AM UTC by john comment:1

owner: → john

Changed July 31, 2007 02:23AM UTC by john comment:2

resolution: → fixed
status: newclosed

Fixed in SVN rev [2529].

Changed February 28, 2011 10:57PM UTC by anonymous comment:3

this appears to be broken again :)

Changed September 07, 2011 03:37PM UTC by anonymous comment:4

It's broken again

Changed February 16, 2012 08:06AM UTC by anonymous comment:5

Still broken! :/

Changed February 16, 2012 01:57PM UTC by dmethvin comment:6

If something is broken we will need a test case. This one works fine for me:

http://jsfiddle.net/pj55k/

You *must* have an href for the element to be focusable.

Changed May 21, 2013 01:41PM UTC by anonymous comment:7

You should write like that

<script type="text/javascript"><![CDATA[

$(window).load(function () {

$("#YourID").focus();

});]]>

</script>