-1
I need horizontally remove one DIV
. The problem that is occurring is that clicking remove is being removed the entire column of DIV
.
HTML
<div class="engloba-tudo">
<div class="produtos container-cart"></div>
<div id="a" class="subtotal">$</div>
</div>
<div class="item flex">
<div class="caixinha" onclick="comprar(1)" id="1">
CARRINHO
</div>
</div>
CSS
.engloba-tudo {
position: fixed;
bottom: 0;
right: 0;
width: 30%;
border-left: 1px solid #333;
border-right: 1px solid #333;
border-bottom: 1px solid #333;
background: #eee;
z-index: 9999;
}
.subtotal {
width: 100%;
border-top: 1px solid #333;
padding: .7rem;
cursor: pointer;
box-sizing: border-box;
flex-direction: column;
text-align: center;
}
.img-info, .preco-info, .x-info {
margin: 5px;
padding: 4px;
border: 1px solid grey;
width: 25%;
cursor: pointer;
}
.container-cart {
max-width: 400px;
margin: 0 auto;
display: flex;
border: 1px solid red;
flex-direction: column;
}
.linha {
width: 100%;
flex-wrap: wrap;
flex-direction: row;
display: flex;
}
.item-cart {
flex: 1;
margin: 5px;
text-align: center;
font-size: 1.5em;
width: calc(33% - 5px);
}
.fas {
font-size: 50px;
}
JQUERY
var objetos = Array();
$(".subtotal").click(function () {
$(".produtos").slideToggle(300);
})
function comprar(c) {
if (c === 1) {
var preco = '5,00';
objetos.push(preco);
var total = objetos.reduce(function (anterior, atual) {
return parseFloat(anterior) + parseFloat(atual);
});
document.getElementById("a").innerHTML = '$ ' + total;
}
}
$('#1').click(function () {
var html = '<div class="linha">'
+ '<div class="item-cart img-info">img</div>'
+ '<div class="item-cart preco-info">preço</div>'
+ '<div class="item-cart x-info" onclick="remover(this)">x</div>'
+ '</div>';
$('.produtos').append(html);
});
function remover(elemento) {
elemento.parentNode.remove();
objetos.splice(0,1);
var total = objetos.length ? objetos.reduce(function(anterior, atual) {
return parseFloat(anterior) + parseFloat(atual);
}) : '';
document.getElementById("a").innerHTML = '$ ' + total;
}
Could you format the code? for better understanding
– Vinicius Farias
sorry, error, link in codepen https://codepen.io/anderson-garden/pen/EzVMxj
– Anderson Garden
@Andersongarden I suggest to you that before creating a publication, read this link carefully.
– user148754