[jQuery] filter() on attributes?

[jQuery] filter() on attributes?

Hi,
I don't want to assign an id attribute to all my <input> fields, but
instead want to do something like this:
<div id="foo">
<input ... name="bar">
</div>
Then, get the value with something like:
$("#foo input[name=bar]").val();
That didn't work. So, I tried:
$("#foo input").filter("[name=bar]").val();
That didn't work either. I'm thinking I might have to use $.grep() but
I can't seem to get it to work:
$.grep($("#foo input"), function(a, i) { return (a[i].attr("name") == "bar"); })[0].val();
That one causes a JS error complaining that "a[i] has no properties."
The filter() docs say I should be able to use an XPath expression ...
so, this should work:
$("#foo input").filter("/[name=bar]").val();
Aha! It does. Is this the best way of doing this? Are there any
pitfalls I need to worry about? Can I collapse this into a more concise
form?
-- Dossy
--
Dossy Shiobara | dossy@panoptic.com | http://dossy.org/
Panoptic Computer Network | http://panoptic.com/
"He realized the fastest way to change is to laugh at your own
folly -- then you can let go and quickly move on." (p. 70)
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/