jQuery: The Write Less, Do More JavaScript Library

Ticket #2352 (closed bug: fixed)

Opened 6 months ago

Last modified 4 months ago

Simulated click event on anchors in IE6 does not work

Reported by: MovinVan Assigned to: brandon
Type: bug Priority: major
Milestone: 1.2.4 Component: core
Version: 1.2.2 Keywords: click, ie6, fireEvent, this
Cc: Needs: Review

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

Change History

Changed 6 months 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.

Changed 6 months ago by brandon

  • owner set to brandon

Changed 6 months 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.

Changed 4 months ago by brandon

  • status changed from new to closed
  • resolution set to fixed
  • summary changed from Simulated Click event in IE6 with $(this).prev() does not work to Simulated click event on anchors in IE6 does not work

Fixed in REV 5273.

Note: See TracTickets for help on using tickets.