0

I have the following code snippet

$("#personalizacoesOpcionais")
      .find(".qtdPersonalizacao")
      .each(function (n, t) {
         var i = {};
         i.IdProdutoIngrediente = parseInt($(t).attr("data-id"));
         i.Qtde = parseFloat($(t).text());            
         r[n] = i
       });

In the html there are several divs personalizacoesOpcionais and each one with numerous elements qtdPersonalizacao.
However, the code snippet above only returns the first item qtdPersonalizacao within the first personalizacoesOpcionais.

Mister Jojo
  • 20,093
  • 6
  • 21
  • 40

1 Answers1

2

However, the code snippet above only returns the first item qtdPersonalizacao within the first personalizacoesOpcionais.

Ids are supposed to be unique within a document and jQuery will just returns the first matching element.

The recommended solution would be to use a class instead of an id for personalizacoesOpcionais.

If this is not possible, for example if you don't control the code that generate the markup, a workaround would be to use $("div[id=personalizacoesOpcionais]") instead of $("#personalizacoesOpcionais")

Anthony Garcia-Labiad
  • 3,531
  • 1
  • 26
  • 30