Side navigation
#2636 closed bug (duplicate)
Opened April 02, 2008 01:40PM UTC
Closed April 22, 2008 05:58AM UTC
Different behavior for .click() triggers in IE 6.0 (7.0) and FF 2.0
Reported by: | smallhorse | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.2.4 |
Component: | event | Version: | 1.2.3 |
Keywords: | click, trigger | Cc: | |
Blocked by: | Blocking: |
Description
If you create a tag like this
<a href="#" id="test" onClick="alert('Test');">Test</a>
and then a jQuery method
$(document).ready(function(){ $("#test").click(); //or $("#test").trigger("click"); });
It will display the alert in FF, but not in IE.
The reason for this can be found in the "trigger" method of jQuery.
The line
fn = jQuery.isFunction( elem[ type ] || null )
returns true in IE, but false in FF if the type==="click" because in IE there is a default click() method in every DOM element.
1) In FF
the trigger method of jQuery does not find a "click" function defined in the DOM Element (fn===false) and therefor checks the "onclick" attribute, finds it and calls the function. --> CORRECT
// Handle triggering native .onfoo handlers if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false ) val = false;
2) In IE
the trigger method of jQuery DOES find a "click" function (which exists in all IE DOM Elements!). This means fn===true. JQuery now ignores the "onclick" attribute and falls back to this.
// Trigger the native events (except for clicks on links) if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
Since our tag is "A" and the type is "click" no action will be performed!
A workaround
for this problem currently is:
$("#test").trigger("onclick");
Attachments (0)
Change History (1)
Changed April 22, 2008 05:58AM UTC by comment:1
resolution: | → duplicate |
---|---|
status: | new → closed |
Duplicate of #2352 which was fixed in Rev [5273].