0

I'd like to be able to have an array full of jQuery selectors as such (an array of class names). This is what I'm doing at the moment though it's not functioning:

var array = [$('.one'),$('.two')];
array[0].find('.box-text').attr('src',"myImage.png");

What's wrong?

3
  • 2
    That should work as long as the elements exist Commented Jan 24, 2013 at 3:46
  • 1
    an array of class names, actually that's an array of jQuery objects and it works jsfiddle.net/nWwtN Commented Jan 24, 2013 at 3:47
  • 1
    Wow. Stupid mistake on my end. .box-text needed to be box-image. Commented Jan 24, 2013 at 3:53

1 Answer 1

5

is it ok for you to do something like

var array = ['.one','.two'];
$(array[0]).hide()
Sign up to request clarification or add additional context in comments.

1 Comment

And for those that would want to perform an action on all of those selectors, here is a sample: $(array.join()).show();

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.