It would also make the very convenient :input selector more useful. Consider:

var formEls = {};
$(':input',myForm).each(function(){
    if(var thisVal = $(this).val())
        formEls[this.name] = thisVal;
});

I'm considering that if "this" were an unchecked checkbox or radio
button that it would return false.  That is, of course, not how it
would have to work. I'm just theorizing.

On 11/15/06, Dave Methvin <[EMAIL PROTECTED]> wrote:
>
> > Currently val() is only a shortcut, but doesn't encapsulate anything
> > useful. It would be nice to have it handling some more stuff.
> > I wouldn't like to have it in an external plugin, that makes it difficult
> > to access or find it when you actually need that functionality.
>
> Right now val() is a macro that means .attr('value') and I agree it isn't
> pulling much weight. Without a rescue it looks like it will be gone in
> jQuery 1.1. But there is probably some way only a few characters longer that
> could do the job.
>
> > - multiple select: Get it's option:selected children and put their
> > values into an array, empty array when nothing is selected
>
> I would rather provide an .attrs() method that returned an array of
> attributes from each of its elements. That is more general and more
> deserving of being in the core IMO. Then you could use it like this:
>
> $("[EMAIL PROTECTED] option:selected").attrs("value");
>
> > - radio: Find the input:radio siblings with the same name and get
> > the value from the one that is checked, ??? when nothing is selected
>
> $("[EMAIL PROTECTED]:checked").attr("value");
>
> > - checkbox: combination of radio and select: Find input:checkbox
> > siblings that are checked and put their values into an array,
> > empty array when nothing is checked
>
> $("[EMAIL PROTECTED]:checked").attrs("value")
>
> > - everything else: stick to the simple value
>
> $("[EMAIL PROTECTED]").attr("value")
>
> I know they are slightly longer but they are also self-documenting. Once you
> know how the basic concepts of selectors and two methods you are golden.
> With a special val() method we are headed down the road of having a core
> full of unique special-purpose methods that each need to be documented as to
> their behavior.
>
>
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to