2
Hello.
I’m hitting myself to create a button for every result that the $.each generates.
 $.each (data, function(index, orc){
           $html += '<div>';
           $html += '<button type="button" class="list-group-item" id="btn_orc'+orc.numero+'">Número: ' +orc.numero+'</br>Data: '+orc.data+'</br>Validade: '+orc.validade+'</br>Total: R$'+orc.total+'</br>'+'</button>';
           $html += '</div>';
    });
    $('#lista').html($html);
   // aqui não sei como implementar
   $('#btn_orc').on('click', function(){
        window.alert("clicou");});
Someone could give me a boost?
Instead of using
$("#lista").html($html);, use the "append" method, thus$("#lista").append($html);, because the way you’re doing, every time he’s replacing the last html added.– Douglas Garrido
Vlw. I will make the change.
– MarcelP
If it works, let me know to mark it as a response. See more information here if you need: W3schools - jQuery DOM Add.
– Douglas Garrido
Your code works: https://jsfiddle.net/6osc71sv/ What exactly is the problem you are experiencing?
– BrTkCa
I cannot create an id for the button it generates with each result. I can’t tell the id of the button, id="btn_orc'+Orc.numero+'", but I can’t use it.
– MarcelP
It is generating correctly, can edit your question by placing the code snippet that is trying to use it?
– BrTkCa
put there ;).
– MarcelP