I've been working through this and I'm a little stuck. I can't seem to find a direct answer so I'm gonna ask.
I'm creating an options list from a JSON call. I've created the child elements but I can't seem to add the unique ID's (stored in the JSON) to each element. When I create the ID inside the $.each of the JSON I get the last ID from the call assigned to all the options.
Thanks
$("#fDistList").append('<option>' + item.GROUP_NAME + '</option>');
$("option").attr('id', item.ID);
                You could do it like this, in a single pass
$('<option/>',{
        text: item.GROUP_NAME, 
        id:item.ID
    }).appendTo('#fDistList');
                        Try this
$("#fDistList").append('<option id="'+ item.ID + '">' + item.GROUP_NAME + '</option>');
When you do
$("option").attr('id', item.ID);
you are reselecting all option elements and setting their ID attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With