user1002039
user1002039

Reputation: 860

JQuery Combining Variable With String

I'm trying to make the following work but can't figure out how to combine variables with string. I've commented the areas I don't understand below.

Thank you!

$('.mcTransferGroup').each(function() {
    var mcAdd = $(this).find('#mcAdd');
    var mcRemove = $(this).find('#mcRemove');
    var mcSelect1 = $(this).find('.mcSelect1');
    var mcSelect2 = $(this).find('.mcSelect2');

    $(mcAdd).click(function() {
        // below here
        $(mcSelect1, 'option:selected').remove().appendTo(mcSelect2);
    });
    $(mcRemove).click(function() {
        // and here ...
        $(mcSelect2, 'option:selected').remove().appendTo(mcSelect1);
    });
});

Upvotes: 0

Views: 630

Answers (2)

sje397
sje397

Reputation: 41802

Try e.g.:

$('option:selected', mcSelect1).remove().appendTo(mcSelect2);

The context should be the second argument.

Here's an example: http://jsfiddle.net/ZbZx9/

Upvotes: 1

oryol
oryol

Reputation: 5248

Use http://api.jquery.com/find/ (for finding element inside given element) and http://api.jquery.com/filter/ (to filter existing jQuery selection).

Upvotes: 0

Related Questions