<!DOCTYPE html PUBLIC "- "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">
$(
function(){
var jValues = $( "#values" );
var jTemplate = $( "#template" );
var intCount = 0;
$( "button" ).click(
function(){
jElement = jTemplate.template(
eval( "(" + jValues.val() + ")" )
);
intCount++;
$( "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>