File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes jQuery selector using array of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "jQuery selector using array of objects" Watch "jQuery selector using array of objects" New topic
Author

jQuery selector using array of objects

James Patrick
Greenhorn

Joined: Feb 07, 2010
Posts: 5
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?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 07, 2010
Posts: 5
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

Joined: Feb 07, 2010
Posts: 5
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56153
    
  13

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: jQuery selector using array of objects
 
Similar Threads
rich:hotKey worked when using jQuery?
Creating a masked popup in JavaScript
Calling a new JSP form a Spring Controller using Ajax
Is there something better then event.pageX/Y?
Jquery form validation