Skip to main content

Bug Tracker

Side navigation

#2352 closed bug (fixed)

Opened February 15, 2008 09:38PM UTC

Closed April 21, 2008 08:41PM UTC

Last modified March 15, 2012 10:02AM UTC

Simulated click event on anchors in IE6 does not work

Reported by: MovinVan Owned by: brandon
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.2
Keywords: click, ie6, fireEvent, this Cc:
Blocked by: Blocking:
Description

I am using jQuery v. 1.2.2 minified

The following code block finds the 'H2.hdr' siblings for every 'a.trigger' in the document and adds a click event. When the H2 is clicked, it should get its previousSibling anchor tag element (there is only ONE in the document) and simulate a click. This works in Firefox but not in Internet Explorer 6.

$('a.trigger').siblings('h2.hdr').bind('click',function(){

$(this).prev('a').click();

}

HTML:

<div>

<a href="link.html" class="trigger">test</a>

<h2 class="hdr">click me to trigger my previousSibling link</h2>

</div>

I found a workaround for this while still using the jQuery selectors:

$('a.trigger').siblings('h2.hdr').bind('click',function(){

if(document.createEventObject){

var thisID = $(this).prev().attr("id");

document.getElementById(thisID).fireEvent("onclick");

}else if (document.createEvent){

$(this).prev('a').click();

}

});

If it is run in IE6 it executes the fireEvent and if its in Gecko/Mozilla it will use jQuery's click.

Attachments (0)
Change History (4)

Changed February 17, 2008 06:29PM UTC by brandon comment:1

Triggering the click event in IE was disabled because it would actually follow the link unlike the other browsers. I'm curious if your workaround has the same affect or if it just fires the handlers.

Changed February 17, 2008 06:30PM UTC by brandon comment:2

owner: → brandon

Changed February 28, 2008 07:04PM UTC by MovinVan comment:3

If that was the case, would using StopPropogation or return false if you didn't want the default action to take place? I was using this for a trigger that had a href attribute value of "#", so I didnt have to deal with that issue.

Changed April 21, 2008 08:41PM UTC by brandon comment:4

resolution: → fixed
status: newclosed
summary: Simulated Click event in IE6 with $(this).prev() does not workSimulated click event on anchors in IE6 does not work

Fixed in REV 5273.