• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

jQuery selector using array of objects

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use jQuery to select objects by passing in an array of object id's. jQuery does not find any elements if the pound sign '#' is included in the array objects ["#one", "#two"] and I use them directly as the selectors, but if I use ["one", "two"] and prepend the pound sign to the objects to form the selectors then it works.

For example in the following code the array of id's is ["one", "#two"], which become the jQuery selectors "#one" and "#two", but only div #one gets updated. What is wrong with the selector for #two?

 
Marshal
Posts: 67363
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than an array, why aren't you using a simple comma-separated list to specify multiple selectors?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're logging the selector variable, which will lead you astray.
In JavaScript, always examine what you actually mean to examine.

Fortunately, you're reinventing the wheel.
 
James Patrick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Rather than an array, why aren't you using a simple comma-separated list to specify multiple selectors?



This was a simplified example of the problem I was having. What I am really trying to do is use jQuery's index function to get column indexes from a table. I used an array so I could get the column indexes one by one.
 
James Patrick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:You're logging the selector variable, which will lead you astray.
In JavaScript, always examine what you actually mean to examine.

Fortunately, you're reinventing the wheel.



Thanks for the Tip! I'm not quite sure what you mean that I'm reinventing the wheel?
 
Bear Bibeault
Marshal
Posts: 67363
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Patrick wrote:What I am really trying to do is use jQuery's index function to get column indexes from a table. I used an array so I could get the column indexes one by one.


OK, this still doesn't tell me much of what you are trying to do, but regardless, jQuery doesn't support an array of selectors as input. To select multiple elements you write a selector that matches the elements. The aforementioned comma operator can come in handy if the elements are completely disparate and cannot be selected using a simpler notation.

You may be getting confused by the fact that jQuery can accept and wrap an array of DOM elements. But that's not the same as an array of selectors.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Patrick wrote:I'm not quite sure what you mean that I'm reinventing the wheel?


Well, not literally. I hope.

I mean that you're doing something one way, yourself/by-hand/manually, which Bear has already mentioned is already supported in a different way. Since we don't know what you're *actually* trying to do, we don't know if there's a better way to do it, like selecting by a class name, etc.
 
If you like strawberry rhubarb pie, try blueberry rhubarb (bluebarb) pie. And try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!