Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple append not working jQuery

I have two comboboxes that I need to populate with the same information when another combobox data is changed.

However, when I use the .append() method, it's apparent that it only executes the latest append call. Here is the code:

    $('.sc-days').change(function () {
        var scedo = $('.sc-edo');
        var sclpo = $('.sc-lpo');
        var selected = $(".sc-days option:selected");
        scedo.append(selected);
        sclpo.append(selected);
    });

When this is run, only 'sclpo' will be populated. You can see the results here. http://jsfiddle.net/DF42s/

like image 509
prog_24 Avatar asked Apr 19 '26 03:04

prog_24


1 Answers

Assuming you intended to append copies of the original, do this:

$('.sc-days').change(function () {
    var selected = $(".sc-days option:selected");
    $('.sc-edo').append(selected.clone());
    $('.sc-lpo').append(selected.clone());
});
like image 100
cookie monster Avatar answered Apr 20 '26 16:04

cookie monster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!