JSFiddle - React, Tailwind, and code Playground
HTML
<div id="holder"></div>
CSS
div {
display: inline-block;
}
#grocery_item {
display: block;
margin: 10px 0;
}
#grocery_item div {
padding: 0 5px;
border: 1px solid black;
}
JavaScript
var grocery_list = {
"Banana": { category: "produce", price: 5.99 },
"Chocolate": { category: "candy", price: 2.75 },
"Wheat Bread": { category: "grains and breads", price: 2.99 }
};
// Create a div element with jQuery that will hold all items.
var $tree = $('<div>', {id: 'items-tree'});
//Loop all items and create elements for each
for (var key in grocery_list) {
var $gItem = $('<div>', {
id: 'grocery_item',
class: 'container'
});
var $item = $('<div>', {
class: 'item'
}).text(key);
$gItem.append($item);
var $category = $('<div>', {
class: 'category'
}).text(grocery_list[key].category);
$gItem.append($category);
var $price = $('<div>', {
class: 'price'
}).text(grocery_list[key].price);
$gItem.append($price);
$tree.append($gItem);
}
$('#holder').append($tree);