This example uses 3 documents

To summarize the script inajax2.js gets the information out of test.html and puts it in the DOM tree of this document (namely in the p tag with id of "ajaxholder"). If no target element is given the output will be handled with a javascript alert.

This method is clearly an improvement over the previous version as far as reusability of code. In the previous version a new function would have be coded for any given document. The same goes for this version as far as the listener goes, however the addition of this listener allows us to remove javascript from the html. Seperation of content and behavior oh my!

P.S. This method is taken and slightly improved upon from an article on sitepoint.