Hello World Bookstore Example
The code below is a bare bones, standalone web page with the all CSS and JavaScript (including loading jQuery and dna.js) to demonstrate dna.js in action.
Each call to dna.clone()
creates a new element from the book
template and appends the element to the books
element.
Bookstore Code
<!doctype html>
<!-- - - - - - -->
<!-- Bookstore -->
<!-- - - - - - -->
<html>
<head>
<meta charset=utf-8>
<title>Bookstore</title>
<link rel=stylesheet href=https://cdn.jsdelivr.net/dna.js/1.2/dna.css>
<style>
body { font-family: sans-serif; margin: 30px; }
.books { width: 250px; }
.book { background-color: gold; padding: 10px; margin: 15px; }
</style>
</head>
<body>
<h1>Bookstore</h1>
<div class=books>
<div id=book class=dna-template>
<div>Title: <span>~~title~~</span></div>
<div>Author: <span>~~author~~</span></div>
</div>
</div>
<script src=https://cdn.jsdelivr.net/jquery/3.1/jquery.min.js></script>
<script src=https://cdn.jsdelivr.net/dna.js/1.2/dna.min.js></script>
<script>
var books = [
{ title: 'The DOM', author: 'Jan' },
{ title: 'Howdy HTML5', author: 'Ed' },
{ title: 'Styling CSS3', author: 'Abby' }
];
dna.clone('book', books);
</script>
</body>
</html>
Bookstore Web Page
Bookstore on jsFiddle
Experiment with the code at: