Thread: jQuery Detect anchor click
View Single Post
Old 10-24-2012, 12:01 AM   PM User | #5
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,615
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by WolfShade View Post
I tried your suggestion (using on instead of each) and put it inside (at the end) of the function that inserts the anchors into the div. Still not firing, for some reason.
No, with the on() function in my edited part of the post I meant to just replace that with the current each loop set-up you have.

On the other hand: Is this where the links are created?
Code:
return "<a href= blah blah blah blah blah > NAME </a>";
If that’s the case – or generally – you should work with “regular” DOM methods rather than with innerHTML type methods. For example you can do:
PHP Code:
$('#devSection').append(
  $(
'<a>', {
    
hrefblabla,
    
textNAME,
    
click: function() {
      
// do whatever you wanna do on click
    
}
  })
); 
Using prepend() and append() you can not only add single elements to a container, you can also add document fragments you stored in a variable, e. g.:
PHP Code:
var fragment = $('<div>', {id'example'}).append($('<a>', {href'http://example.com'text'whatever'}));
$(
'#container').append(fragment); 
will result in
Code:
<div id="container">
  <div id="example">
    <a href="http://example.com">whatever</a>
  </div>
</div>
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
WolfShade (10-24-2012)