This one has been driving me nuts. I have a div that has it’s content loaded via Ajax when the page loads. The contents of the div are several hyperlinks. I am trying to get the HREF value of the clicked link using $(this).attr('href'). However, this always returns “undefined”. I am guessing, since the hyperlinks were dynamically loaded via Ajax, jQuery is unable to return the HREF value. I have checked the page source and confirmed that all hyperlinks carry valid HREF links.
How can I retrieve the HREF values for hyperlinks dynamically loaded via Ajax?
use jQuery on to bind the click function
http://api.jquery.com/on/
As of jQuery 1.7, the .live() method is deprecated.