Page 1 of 1

too much recursion

Posted: Thu Oct 21, 2010 10:09 pm
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?

Re: too much recursion

Posted: Thu Oct 21, 2010 11:14 pm
by John Cartwright
Attach the click event directly to the cross-link class, instead of the document body.

Re: too much recursion

Posted: Sun Oct 24, 2010 11:08 pm
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.

Re: too much recursion

Posted: Mon Oct 25, 2010 5:30 am
by Eran
If anchors are added dynamically, use live events -

Code: Select all

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