Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#2352 closed bug (fixed)

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.

Change History (4)

comment:1 Changed 12 years ago by brandon

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.

comment:2 Changed 12 years ago by brandon

Owner: set to brandon

comment:3 Changed 12 years ago by MovinVan

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.

comment:4 Changed 12 years ago by brandon

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.

Note: See TracTickets for help on using tickets.