Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#11326 closed bug (invalid)

Triggering click on anchor target does not follow link

Reported by: anonymous Owned by: anonymous
Priority: low Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

Description

Given the markup:

<a href="/somelink"></a>

and the JS:

$('a').click();

the default action is not executed.

On the other hand, given the markup:

<a href="/somelink"><span></span></a>

and the JS:

$('span').click();

the default action of the anchor is executed--the link is followed.

The problem code can be found at line 3158 in 1.7.1--it specifically filters out this case:

(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem )

This is inconsistent and is causing me some pain. Please remove it.

Change History (6)

comment:1 Changed 11 years ago by addyosmani

Owner: set to anonymous
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:2 Changed 11 years ago by bklaas

I've come across this same problem, and am currently working around it by creating inner spans within my a tags.

reduced test case here http://jsfiddle.net/bklaas/FrKyN/253/

the top link has an event handler that issues a .click() on the second link notice the user is not sent to the target of the second link

Last edited 11 years ago by bklaas (previous) (diff)

comment:3 Changed 11 years ago by dmethvin

This behavior of .trigger() is from #873 introduced in version 1.2 (September 2007) and provides consistent cross-browser results. Only Internet Explorer has a DOM .click() method, but other browsers do not.

http://jsfiddle.net/dmethvin/v7LKF/ Link only http://jsfiddle.net/dmethvin/v7LKF/1/ Span in a link

Note that your event handler can do something simple like document.location.href = this.href if you want to follow the link in all browsers.

bklaas, your test case did not come through. I would be interested in seeing it.

comment:4 Changed 11 years ago by trac-o-bot

Resolution: invalid
Status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

comment:5 Changed 11 years ago by yiminghe

i think that line of code should be removed too, refer:

https://developer.mozilla.org/en-US/docs/DOM/element.click

comment:6 Changed 11 years ago by dmethvin

See #12652

Note: See TracTickets for help on using tickets.