The product disappears from the cart after clicking on Add to Cart, but it doesn't reappear when clicked again.
//function for adding only one item to cart
document.getElementById('btn1').onclick = function() {
addItemToCart()
};
function addItemToCart() {
var x = document.getElementById('itm_img');
document.getElementById('itm1').innerHTML = x.innerHTML;
document.getElementById('rtm').style.display = "block";
}
// function for removing item from cart
document.getElementById('rtm').onclick = function() {
removeItemFromCart()
};
function removeItemFromCart() {
document.getElementById('itemshow').style.display = "none";
}
.all {
display: flex;
}
.item_container {
display: flex;
flex-direction: column;
background-color: #ffcccc;
width: 250px;
border-radius: 6px;
box-shadow: 10px 10px 30px;
align-items: center;
margin: 5%;
}
.itm_img {
padding: 2%;
}
.img {
width: 200px;
border-radius: 5px;
}
.itm_title {
text-align: center;
}
h3 {
font-family: 'Roboto', sans-serif;
margin-bottom: 0%;
}
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
</head>
<body>
<div class="all">
<div class="item_container">
<div class="itm_img" id="itm_img">
<img src="https://m.media-amazon.com/images/I/61X1b09mK0L._SL1500_.jpg" alt="img" class="img" id="img">
</div>
<div clas="itm_dtl">
<div class="itm_title" id="itm_title">
<h3> Milton stainless steel Water Bottle, 1 pc, 950 ml, Silver</h3>
</div>
<div class="link">
<a href="https://www.milton.in/">Visit Milton Store</a>
</div>
<hr>
<div class="price">$19</div>
<div class="btn">
<button class="btn1" id="btn1">Add to Cart</button>
</div>
</div>
</div>
<div class="item_container">
<div class="itm_img">
<img src="https://m.media-amazon.com/images/I/61X1b09mK0L._SL1500_.jpg" alt="img" class="img">
</div>
<div clas="itm_dtl">
<div class="itm_title">
<h3> Milt# # on stainless steel Water Bottle, 1 pc, 950 ml, Silver</h3>
After adding the item to the cart and then removing it using the provided button, trying to add it back by clicking Add to Cart does not work as expected.