Hi,
In jQuery, what is the equivalent to document.getElementById("selectlist").value ?
I am trying to get the value of a select list item.
Thanks.
Hi,
In jQuery, what is the equivalent to document.getElementById("selectlist").value ?
I am trying to get the value of a select list item.
Thanks.
Chaos is spot on, though for these sorts of questions you should check out the Jquery Documentation online - it really is quite comprehensive. The feature you are after is called 'jquery selectors'
Generally you do $('#ID').val() - the .afterwards can do a number of things on the element that is returned from the selector. You can also select all of the elements on a certain class and do something to each of them. Check out the documentation for some good examples.
In some cases of which I can't remember why but $('#selectlist').val() won't always return the correct item value, so I use $('#selectlist option:selected').val() instead.
"Equivalent" is the word here
While
$('#selectlist').val();
is equivalent to
document.getElementById("selectlist").value
its worth noting that
$('#selectlist')
although 'equivalent' is not the same as
document.getElementById("selectlist")
As the former returns a jQuery object, not a DOM object.