Thread: jQuery Detect anchor click
View Single Post
Old 10-23-2012, 09:45 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
First of all, live() is deprecated as of jQuery 1.7, you should use on() if you’re using a recent version of jQuery.

Then, your problem is that each() loop which, as you correctly noted, doesn’t know about the non-existing anchors yet. Therefore, you need to add the click function/event to the function that creates/appends the links in the first place. Can you show us how the div is populated with the anchors?

Edit:
Oh, it might even be simpler: just don’t use each() but on() in the first place
PHP Code:
$('.remLink a').on('click', function(e){
  
e.preventDefault();
  $(
'#chgWarning').html("Changes to this record have not been saved");
}); 
But still, if you insist in using each() for whatever reason, you should add the click event when the anchors are created/appended as this each loop only accounts for the elements already existing.
__________________
Don’t click this link!

Last edited by VIPStephan; 10-23-2012 at 09:48 PM..
VIPStephan is offline   Reply With Quote