Here's an alternative approach that was not mentioned:
If you are using jQuery v1.7 + , you can use the .on() method to bind the event listener to the current HTML, as well as HTML added in the future:
$('#message a').on('click', function(){ alert('link clicked!'); });
If you are using an older version of jQuery, it is recommended that you use .delegate() :
$('#message').delegate('a', 'click', function(){ alert('link clicked!'); });
In short:
$(elements).delegate(selector, events, data, handler); // jQuery 1.4.3+ $(elements).on(events, selector, data, handler); // jQuery 1.7+
source share