I know that it does what it says it does. That's not the point.
The point is that it only works on the input element.
No, it will return the "value" attribute for any element. I think it would
have been clearer what was going on if .val() did not exist and people used
.attr("value") instead.
I'm sorry, but I think that should be spelled out.
Obviously a number of people thought it would retrieve the
value of the selected option(s) in a select (or multiple select)
box and that it would retrieve all text between the opening
and closing textarea tags.
Agreed, that's one of my primary motivations for saying all the macro
properties should go. To save a few characters we've created a documention
burden and a much greater chance of misinterpretation. Plus, someone has to
implement all that special-case code if we really want it to work that way.
What would be wrong with adding those? There's probably a
perfectly good reason, I just don't know what it is.
We already have one, albeit with a longer name. Grab the form plugin and
take a look at formToArray. It returns all the useful values out of a form
as name/value pairs. Since .val() is form-related it seems like this would
be the appropriate home for something fancier than .attr("value) usage.
The API also does not discuss here what this method
returns if the input is a check box or radio button. Does
it return that it is checked (like f.mycheckbox.checked)?
$("input:checkbox").val() will return the value of the checkbox whether it
is checked or not, since it is the same as
$("input:checkbox").attr("value"). In HTML the value attribute doesn't
change depending on whether the box is checked or not. You'd need to look at
$("input:checkbox").attr("checked") to determine that.
Again, I think this is just one more reason to abandon .val() because it is
much more confusing than .attr("value"); most people understand the concept
of getting the attribute of an element and it's not a jQuery-specific
concept.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/