//XML string with all whitespace and cariage returns removed
var txt="<store><item><description>Chair</description><cost>100.00</cost><image>chair.jpg</image></item><item><description>Table</description><cost>1500.00</cost><image>table.jpg</image></item><item><description>Lamp</description><cost>50.00</cost><image>lamp.jpg</image></item></store>";
// parse the store and create the icons
loadStore(txt);
// Load icons for each item in the store
function loadStore (txt) {
var xmlDoc = parseXMLDoc(txt);
var theStore = xmlDoc.getElementsByTagName("item");
// Iterate through each item in the store, creating a tumbnail view for each
for (var i=0 ; i<theStore.length ; i++) {
// Get data for the current item
var item = theStore[i];
var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
var cost = item.getElementsByTagName("cost")[0].childNodes[0].nodeValue;
var image = item.getElementsByTagName("image")[0].childNodes[0].nodeValue;
addItem(description, cost, image);
}
}
// Create the icons for a given product
function addItem(description, cost, image) {
var imageDir = "http://www.bvonkonsky.com/images/bwt/";
// Create a new div for the thumbnail for this item
var divElement = document.createElement("div");
// This div is of class product
divElement.setAttribute("class", "product");
// Set callback designating action when product is clicked
var callback = "alert('" + description + ", $'+" + cost + ")";
divElement.setAttribute("onclick", callback);
// Create the image for the item tumbnail and apend it to the di
var imgElement = document.createElement("img");
imgElement.src= imageDir + image;
divElement.appendChild(imgElement);
// Create the label for the item thumbnail and append it to the div
var label = description + ", $" + cost;
var pElement =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.