the value attribute doesn't change if you type something in a <input
type="text" /> node.
The value attribute is used by the browser as the defaultValue
attribute of the node while the value attribute always contains the
current value.
Try changing text in a input text and inspect it with Firebug, you'll
notice that the value attribute hasn't changed.
So with .attr('value') you should be able to fetch the default value.
And with .val() the current value.
The same goes for <select> nodes. If you select a different <option>
in a <select>, the selected attribute doesn't get set. Thats why you
have to use the selectedIndex attribute of the select. Afaik jQuery
does exactly that, figure out wich option's index == the selectedIndex
of the <select>
So the if you want to know the default selected option you could do $
('select option[selected]') while if you want to get the current
selected option it would be $('select option:selected')
On 28 mei, 17:51, donb <[email protected]> wrote:
> Isn't this an issue with the DOM of a particular browser -
> specifically, if it simply allows non-'input' type elements to have a
> value attribute, or does not?
>
> An <input> or <select> will have (by its nature) a 'value'. A <div>
> will not. Not until you assign one to it. Or so it seems.
>
> On May 26, 3:47 pm, Alex Farcas <[email protected]> wrote:
>
>
>
> > Further details:
> > This behavior was noticed only in FF browsers.
> > - in FF 2.0.0.12 it is exactly as described in the previous message
> > - in FF 3.0.10 the difference is that val() does not return the value
> > attribute if that attribute is set by html markup, but does retrieve
> > it if it's set with val(). If set with val(), both attr() and val()
> > return the same value.
>
> > I used JQuery 1.3.1 and 1.3.2
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---