1

Never ran into this situation before and now I am having trouble accomplishing this.

I basically want this:

$(cardMonth).prepend("<option value='' selected='selected'></option>");
$(cardYear).prepend("<option value='' selected='selected'></option>");

To be something like this:

$(cardMonth, cardYear).prepend("<option value='' selected='selected'></option>");
3
  • And it doesnt work? Have you tried it? But what are cardMonth and cardYear? Id's or classnames? So its either $('#cardMonth, #cardYear') or $('.cardMonth, .cardYear') Commented Jul 10, 2013 at 22:27
  • They are variables. They work fine separated, but trying to use them in the same line does not work. Commented Jul 10, 2013 at 22:28
  • And where and how did you define the variables? Commented Jul 10, 2013 at 22:31

2 Answers 2

2
$(cardMonth).add(cardYear).prepend("<option value='' selected='selected'></option>");

Alternatively:

var els[0] = cardMonth;
var els[1] = cardYear;
$(els).prepend("<option value='' selected='selected'></option>");
Sign up to request clarification or add additional context in comments.

Comments

1

You need jQuery.merge(), http://api.jquery.com/jQuery.merge/:

$.merge($(cardMonth), $(cardYear)).prepend("<option value='' selected='selected'></option>");

Comments

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.