You should use live () as follows:
$(".links").live('click', function(){alert("aaaa");})
This also works with elements added to the document.
for onclick for each <a> element you should do this (if that's what you mean:
$("a").live('click', function(){ alert($(this).attr("id")); })
This binds the event to all <a> elements, as well as to those added subsequently.
EDIT - now the link identifier is displayed in the message: 'this' in this case refers to the <a> that was pressed
source share