Tuesday, October 3, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  166] [ 2]  / answers: 1 / hits: 34651  / 15 Years ago, tue, june 16, 2009, 12:00:00

I have an array of strings that are valid jQuery selectors (i.e. IDs of elements on the page):

[#p1, #p2, #p3, #p4, #p5]

I want to select elements with those IDs into a jQuery array. This is probably elementary, but I can't find anything online. I could have a for-loop which creates a string #p1,#p2,#p3,#p4,#p5 which could then be passed to jQuery as a single selector, but isn't there another way? Isn't there a way to pass an array of strings as a selector?

EDIT: Actually, there is an answer out there already.

More From » jquery


Well, there's 'join':

[#p1, #p2, #p3, #p4, #p5].join(, )

EDIT - Extra info:

It is possible to select an array of elements, problem is here you don't have the elements yet, just the selector strings. Any way you slice it you're gonna have to execute a search like .getElementById or use an actual jQuery select.

[#99304] Thursday, June 11, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 276
Total Questions: 92
Total Answers: 101

Location: North Korea
Member since Fri, Nov 4, 2022
12 Months ago