The first thing I want ask for advice. I am making shopping cart only on JavaScript and I want to know how organize my application more correct. For example I have two page: product page and basket page. For storing data I use array:
var productId, productName, productSize, productAmount;
var productsData = [];
and I want to put there objects like this:
productsData.push({productId:productId,productName:productName,productSize:productSize,productAmount:productAmount});
I don't know how I can get set of li elements and put them into my object (there is stored each size of shoe). I have created next, but unfortunately it doesn't work:
$('.size').on("click", "a li", function () {
productSize = parseInt($(this).text(), 10);
productsData.push({productSize:productSize});
console.log(productsData[productId]['productSize']);
});
When I will be get whole object I am going to put it into Local Storage and display it on basket page.
Below my html code fragment:
<main class="product-section">
<div class="product-preview" id="item1">
<div class="current-photo-product">
<img src="img/product-photo1.png" alt="Grey">
<img src="img/product-photo2.png" alt="White">
<img src="img/product-photo3.png" alt="Light Blue">
<img src="img/product-photo4.png" alt="Dark Blue">
</div>
<div class="choice-photo">
<ul>
<li><img src="img/product-photo1.png" alt="Grey"></li>
<li><img src="img/product-photo2.png" alt="White"></li>
<li><img src="img/product-photo3.png" alt="Light Blue"></li>
<li><img src="img/product-photo4.png" alt="Dark Blue"></li>
</ul>
</div>
</div>
<div class="product-details">
<div class="wrapper-details">
<h2>New Balance</h2>
<p class="article-number">Article number: 14210160762</p>
<h4 id="amount">€ 99.95</h4>
<p class="description">Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque dui, non felis. Maecenas malesuada elit lectus felis, malesuada ultricies.
</p>
<h3>Size</h3>
<ul class="size" id="listOfSizes">
<a href="#"><li>38</li></a>
<a href="#"><li>39</li></a>
<a href="#"><li>40</li></a>
<a href="#"><li>41</li></a>
<a href="#"><li>42</li></a>
</ul>
<button id="add-to-cart">Add to cart</button>
</div>
</div>
</main>
` and `- ` not valid child of ``