Display JavaScript Source Programatically

23rd March 2009 - 1 minute read time

If you are running a JavaScript example page you can use the following function that will take the last script element on the page and print it out in a code tag. It uses JQuery to do the work, so you will need to include that library before using this function.

  .insertAfter('#display-' + name);

The function works by selecting the current script tag and finding all script elements before it. It then selects the first one it finds and outputs the contents to a code tag. It uses a few regular expressions to convert some of the characters to a more human readable format. The function is called like this.

Add new comment

The content of this field is kept private and will not be shown publicly.