0

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);
    });
});
1
  • Why return in the event handler? Commented Dec 27, 2011 at 11:31

2 Answers 2

1

Try e.g.:

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

The context should be the second argument.

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

But how do I combine a variable with a filter? The manual says nothing about it.
If mcSelect1 is select tag - use mcSelect1.find('...'). If it's already option collection (I can't be sure what it is because you didn't provide HTML code) - use mcSelect1.filter('...').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.