Why can I not insert json data in children of a clone() element?
Why can I not insert sale.title in a clone() element's children, but I can insert it in the main element?
Am I using the wrong approach to HTML-format JSON objects?
The part that I don't understand is shown bellow:
-
element.append(isale.title);
element.children(".sale_title").append(isale.title);
};
This is my code:
- <!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div id="content_bottom">
<div id="recent_sales">
</div>
</div>
<div class="home_sale">
<div class="sale_title"><a href=""></a></div>
<div class="sale_date"><span class="sale_label">Date:</span>
<b>(DATE)</b>
</div>
<div class="sale_detail">
<span class="sale_label">
Location:
</span>(AREA_LINK, STREET ADDRESS)
</div>
<div class="sale_detail">
<span class="sale_label">
Description:
</span>
</div>
</div>
<script type="text/javascript">
var list_html = $("#content_bottom").children("#recent_sales");
single_sale_html = $(".home_sale");
var listing_array = new Array();
data = {"result": "ok", "sales": [{"area": "Autre Quartier", "create_date": "2010-04-28T10:23:04", "description": "RÉFRIGÉRATEUR INGLIS BLANC, 18 PIEDS CUBES 2 ANS USURE, TRES PROPRE, VALEUR 800$ POUR 500$ CUISINI;ERE INGLIS BLANCHE 2 USURE TRES PROPRE VALUER 500$ POUR 300$ LAVEUSE SEARS BLANCHE 30 PO. 2 ANS USURE 250$ SÉCHEUSE SAMSON BLANCHE 150$ LIT À 2 TIROIRS ET MATELAT SIMPLE + LITERIE 125$ LIT KING COULEUR MIEL, MARQUE LAURIER ET MATELAT POUR 800$ CAUSEUSE ET DIVAN JAUNE 400$ TABLE ET CHAISES EN ROTIN 400$ SAC DE GOLF TURQUOISE, BOIS ET FERS, SOULIERS POUR FEMME 100$ AUTRES ARTICLES .......PRIX VARIÉS ", "end_date": "2010-05-25", "title": "22 au 24 mai 2010", "location": "18, claire, St-Sauveur", "id": 20, "start_date": "2010-05-22"}, {"area": "Autre Quartier", "create_date": "2010-04-09T23:13:18", "description": "M.R.U.C. GARAGE AND GARDEN SALE Saturday, May 29, 2010 9am - 3pm Mount Royal United Church 1800 Graham Boulevard Town of Mount Royal, QC H3R 1G9 www.mountroyalunited.ca Great products at exceptional prices that will bring a smile to our customers' faces! - clothing, kitchen items, appliances, electronics, books, DVDs, CDs, toys, sporting goods, linens, furniture, baking Everyone welcome! ", "end_date": "2010-05-29", "title": "May 29 MRUC Garage & Garden Sale", "location": "1800 Graham Boulevard, mount royal", "id": 11, "start_date": "2010-05-29"}]}
sale_list = data["sales"];
for (i in sale_list) {
var isale = sale_list[i];
element = list_html.append(single_sale_html.clone().appendTo(list_html));
element.append(isale.title);
element.children(".sale_title").append(isale.title);
};
</script>
</body>
</html>