too much recursion

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
scifirocket
Forum Commoner
Posts: 31
Joined: Fri Aug 13, 2010 1:24 am

too much recursion

Post by scifirocket »

this code:
[text]$(document).ready(function() {
$('body').click(function(evt) {
if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) {
$('a[href=#2]').trigger('click'); } });});[/text]
given me and error of "too much recursion"

how can i solve this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: too much recursion

Post by John Cartwright »

Attach the click event directly to the cross-link class, instead of the document body.
scifirocket
Forum Commoner
Posts: 31
Joined: Fri Aug 13, 2010 1:24 am

Re: too much recursion

Post by scifirocket »

John Cartwright wrote:Attach the click event directly to the cross-link class, instead of the document body.
elements with the cross-link class are generated after the DOM is loaded. that is why I have this strange code. do you have a better suggestion for my code then? thanks.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: too much recursion

Post by Eran »

If anchors are added dynamically, use live events -

Code: Select all

$('.cross-link').live('click',function() {
   ...
});
Post Reply