On 05/09/06, Dossy Shiobara <[EMAIL PROTECTED]> wrote:
> 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 | [EMAIL PROTECTED] | 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)
>
I use:
$("#foo [EMAIL PROTECTED]").val();
i.e. put @ before the attribute you want.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/