Dynamically triggering combos for DOM creation via jQuery

1

I have a sequence of 3 dropdowns that modify the DOM. One depends on the other. If I select the first dropdown it modifies the DOM and the other dropdowns. The second dropdown modifies the third one in the same way. The question is how to trigger these dropdowns dynamically? I can fill in the first one.

 $('select#initial option[value=' + data[0].initial + ']').attr({ selected : "selected"}).prop('disabled', false);;

But the change event that would mount the DOM from the second dropdown was not triggered.

    
asked by anonymous 22.10.2015 / 03:34

1 answer

1

$(document).ready(function(){
$('#cboEstado')
    .append('<option>São Paulo</option>')
    .append('<option>Rio de Janeiro</option>')
    .append('<option>Minas Gerais</option>');

$('#cboEstado').on('change',function(){

    //Create a new elemment dropdown
    $('<select>')
        .prop('id','cboCidade')
        .append('<option>Araraquara</option>')
        .append('<option>Campinas</option>')
        .insertAfter($('#cboEstado'));

    //Attach event change in the new elemment
    $('#cboCidade').on('change',function(){
        $('<select>')
            .prop('id','cboItems')
            .append('<option>Item 1</option>')
            .append('<option>Item 2</option>')
            .insertAfter($('#cboCidade'));
    });
});

});

Sample code in the link below: link

☜ (゚ ヮ ゚ ☜)

    
22.10.2015 / 15:28