Creating jQuery Templates Plug-in Using Textarea Elements (Thanks Kurt Bonnet)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>jQuery HTML Templates Using Textarea Elements</title>
	<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
	<script type="text/javascript" src="jquery.template.js"></script>
	<script type="text/javascript">
 
		// Hook up the add button handler.
		$(
			function(){
				// Get a refernece to the values text area.
				var jValues = $( "#values" );
 
				// Get a refernece to the template text area.
				var jTemplate = $( "#template" );
 
				// Keep track of the templates created.
				var intCount = 0;
 
				// Bind the click event.
				$( "button" ).click(
					function(){
						// Get the new element from our jQuery
						// template. When we do this, we are going
						// to pass in some values that can be
						// leveraged.
						jElement = jTemplate.template(
							eval( "(" + jValues.val() + ")" )
							);
 
						// Increment the count.
						intCount++;
 
						// Add the element to the page.
						$( "body" ).append( jElement );
					}
					);
			}
			);
 
	</script>
</head>
<body>
 
	<h1>
		jQuery HTML Templates Using Textarea Elements
	</h1>
 
	<form>
 
		<p>
			Please enter your template code in the
		</p>
 
 
		<textarea
			id="values"
			style="width: 500px ; height: 125px ;">
 
			{
				count: intCount,
				name: "Naomi",
				description: "Sexy"
			}
 
		</textarea>
 
		<br />
 
		<textarea
			id="template"
			style="width: 500px ; height: 125px ;">
 
			<p id="template{count}">
				<strong>{name}</strong> is <em>{description}</em>
				I am template {count}.
			</p>
 
		</textarea>
 
		<br />
 
		<button type="button">Add Template</button>
 
	</form>
 
</body>
</html>

For Cut-and-Paste