Javascript document.write help

Hi

I’ve been struggling to adapt this code which pulls in books currently reading from Readernaut. At the moment this will pull in the book cover, but I want to add the title in text next to the cover with a permalink.

I can get the text by using document.write but I can’t work out how to add the element so it’s a link or can be styled with CSS.

Any help much appreciated.

Thanks

function parseResponse(data) {
	var bookshelf = document.getElementById("bookshelf");
	
	for (var i=0; i<1; i++) {
		var cover = data.reader_books[i].book_edition.covers.cover_medium;
		var title = data.reader_books[i].book_edition.title;
		var permalink = data.reader_books[i].permalink;
		
		var link = document.createElement("a");
		link.setAttribute("href",permalink);
		
		var img = document.createElement("img");
		img.setAttribute("src",cover);
		img.setAttribute("alt",title);
					
				
				link.appendChild(img);
				bookshelf.appendChild(link);	
		
	}		
	
}



You will want to add the text to a link element.


var text = document.createTextNode(title);
link.appendChild(text);

You will want to use the lowest common reference to style the links.
If the bookshelf identifier is appropriate for that, then you would use:


#bookshelf a {
    text-decoration: none;
}
#bookshelf img {
    border: 0;
}

Fantastic, thanks so much. Worked a treat!

Leanda