简体   繁体   中英

Having trouble using jquery to click on a link

I'm just trying to click on a link with jquery. Here's my code. When I click on the link manually it works, so I know the link is good.

$(this).find("td:first > * > a").click();

The error I get is Uncaught RangeError: Maximum call stack size exceeded

I can change the code to

$(this).find("td:first > * > a").css('background-color', "red");

and it changes the link background color to red so I know I've successfully selected the anchor. I've researched a lot and found some others having issues with the click() function on links.

Here is a very simple jsfiddle of what I'm trying to do and I can't get it to work. jsfiddle.net/vtLq9/10 When I click the button I want the link to be clicked and be taken to href. Thanks.

Thanks for the help.

Dale

Uncaught RangeError: Maximum call stack size exceeded occurs when your call stack is too deep. This usually means you're calling a function that keeps call itself, possibly via another function.

There must be something else on the page that is interacting with this script. Does your click handler execute the click handle by any chance? ;)

Dale,

Changing your code to use:

window.location = $(this).find("td:first > * > a").attr("href");

is not the preferred way to do this. It would bypass all other event listeners that would have been called and it assumes the link has an absolute path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM