1
How do I clean the edge of a DIV in Loop with jQuery?
For example, I’m with a modal, looping database data with Json, I have a button to select each item returned from that list-(loop), then I did the following, created a class name: borda_310 <- borda_id_do_product, then when I give a select I can create an edge on that loop item, but if I select the other items also selects, ie it gets all selects the ones I clicked, I want you to click one and select, when clicking another selects the other and removes the edge from the previous.
My HTML code:
<div class="col-md-3 li">
<div class="product borda_' + data.dados[a].post_id + '">
<ul class="product-labels">
<li>' + data.dados[a].aluguei + '</li>
</ul>
<div class="product-img-wrap">
<img class="product-img-primary" style="height:150px;" src="<?= BASE; ?>/uploads/' + data.dados[a].post_cover + '" alt="' + data.dados[a].post_title + '" title="' + data.dados[a].post_title + '" />
<img class="product-img-alt" style="height:150px;" src="<?= BASE; ?>/uploads/' + data.dados[a].post_cover + '" alt="' + data.dados[a].post_title + '" title="' + data.dados[a].post_title + '" />
</div>
<div class="product-caption">
<h5 class="product-caption-title">' + data.dados[a].post_title + '</h5>
<div class="product-caption-price">
<span class="product-caption-price-new">
<a data-id_select="' + data.dados[a].post_id + '" class="btn btn-primary selecionar_jogo disabled_'+ data.dados[a].post_id +'" href="#">Selecionar</a>
</span>
</div>
</div>
</div>
</div>
My jquery code:
$(".lista_jogos").on("click", "a.selecionar_jogo", function (e) {
var id_relacionamento = $(this).attr('id-jogo');
var id_jogo = $(this).attr('data-id_select');
$('.borda_' + id_jogo).attr('style', 'border:2px solid red');
//alert(id_relacionamento+' - '+id_jogo);
});
I’m waiting for someone to solve the problem with me.
I think you’re doing it wrong, using unnecessary ids that will only hinder your code. Show HTML to see how the structure of the elements is.
– Sam
I put the HTML there
– Alisson Maciel
Another thing: no need to use different classes just to know what number she has to select:
$('.borda_' + id_jogo)
... elements with the same styles or for the same purpose must have the same class. Distinct identification should be used only with ids, and sometimes not even accurate.– Sam
I actually created this class there just to differentiate at the time of the click, more as I am not an expert in jQuery, I look forward to the help of you and others.
– Alisson Maciel