How to get ID of inputs generated dynamically within DIV ''

0

I would like to know how I can get the hidden input IDs that were generated dynamically within the DIV via Jquery.

I have tried the following but it does not work:

$(document).on('click', '.div_desc_prod', function() {
    alert($(".id_produto").val());
});

Where .div_desc_prod is referenced for each dynamically generated div, and .id_product refers to each input generated within each div dynamically.

I think I could not express my case well ... I do not need to generate the DIVs with dynamic ID's, the DIV's are generated from a selection in the Menu, for example, when selecting in the Menu the Traditional Pizzas Category, will be generated on the screen the amount of DIV with each Pizza within that category in each DIV, and in each DIV already has an input hidden with the ID of each pizza listed. So I need to select the desired pizza ID by clicking on the DIV to play in the shopping cart.

Not only 1 ID, there may be 1 or more, for example:

<div class="div_desc_prod" id="div_desc_produto">
    <input type="hidden" name="id_produto" value="'+ obj.id +'">
</div>

This div can be generated 1 or several times with different IDs, so when I click on a certain DIV I want to get the ID of the one being clicked.

    
asked by anonymous 21.02.2017 / 19:45

1 answer

0

If it's an ID, it has to look like this:

alert($("#id_produto").val());

Updating:

var html;
for(var i=0; i<=$('.div_desc_prod').length; i++){
       html = '<div class="div_desc_prod" id="div_desc_produto'+i+'">'+
              '<input type="hidden" name="id_produto" value="'+ obj.id +'">'+
              '</div>';
       $('.container').append(html);
}
    
21.02.2017 / 19:47