Skip to content

Instantly share code, notes, and snippets.

@bessiec
Created July 9, 2013 00:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bessiec/5953800 to your computer and use it in GitHub Desktop.
Save bessiec/5953800 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="utf-8"/>
<title>My Book List</title>
</head>
<body>
<h1> My Book List</h1>
<script>
var books = [{
title: "Watership Down",
author: "Richard Adams",
alreadyRead: true,
URLimage: "http://d.gr-assets.com/books/1353615493l/76620.jpg"
},
{
title: "James and the Giant Peach",
author: "Ronald Dahl",
alreadyRead: false,
URLimage: "http://readingkingdom.com/blog/wp-content/uploads/2011/05/James-and-the-Giant-Peach.jpg"
},
{
title: "50 Shades of Grey",
author: "Some lady",
alreadyRead: false,
URLimage: "http://vikisecrets.com/uploaded/2012/large/fifty-shades-darker.jpg"
},
{
title: "War and Peace",
author: "Leo Tolstoy",
alreadyRead: true,
URLimage: "http://3.bp.blogspot.com/_6WRcJM7SGZY/S8SIsabXMaI/AAAAAAAAB6k/bXH8e_xDYV4/s200/war-peace.jpg"
}
]
var myBody = document.getElementsByTagName('body')[0];
var list = document.createElement('ul');
myBody.appendChild(list);
for (var i=0; i<books.length; i++){
var temp = document.createElement('li');
temp.innerHTML = "<p>"+books[i].title + " by " + books[i].author+"</p>";
if(books[i].alreadyRead){
temp.setAttribute('style',"text-decoration: line-through");
}
list.appendChild(temp);
var bookcover = document.createElement('img');
bookcover.src = books[i].URLimage;
bookcover.width = 100;
temp.appendChild(bookcover);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment