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?
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
posted
0
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
posted
0
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?
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.
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.