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?
too much recursion
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: too much recursion
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
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.John Cartwright wrote:Attach the click event directly to the cross-link class, instead of the document body.
Re: too much recursion
If anchors are added dynamically, use live events -
Code: Select all
$('.cross-link').live('click',function() {
...
});