Use this to check for dynamically added .test elements:
jQuery("body").on('click', '.test', function() {
jQuery(this).prevAll("input").val("5");
jQuery(".after").append("<div><input /><a class='.test'>click doesn't work !</a></div>");
});
If you are using jQuery less than 1.8 then use live instead:
jQuery('.test').live('click', function() { ...
Basically the reason is because when the DOM loads then the initial click function just applies to elements already IN the document. But with the on() handler you sets a listener to check within the realm (body) which content has the test class and makes the click event work on that...