Bug Tracker

Modify

Ticket #11326 (closed bug: invalid)

Opened 16 months ago

Last modified 7 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 15 months ago by addyosmani

  • Owner set to anonymous
  • Priority changed from undecided to low
  • Status changed from new to pending

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 15 months 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 15 months ago by bklaas (previous) (diff)

comment:3 Changed 15 months 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 14 months ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

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 7 months 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 7 months ago by dmethvin

See #12652

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.