From 61ffc08636ed39b17d828e6406d63631c3f29ade Mon Sep 17 00:00:00 2001
From: Chealer The When the first element in the collection is a For selects and checkboxes, you can also use the :selected and :checked selectors to get at values. For example: For selects, checkboxes and radio buttons, you can also use the :selected and :checked selectors to get at values. For example:.val()
method is primarily used to get the values of form elements such as input
, select
and textarea
. When called on an empty collection, it returns undefined
.select-multiple
(i.e., a select
element with the multiple
attribute set), .val()
returns an array containing the value of each selected option. As of jQuery 3.0, if no options are selected, it returns an empty array; prior to jQuery 3.0, it returns null
.
// Get the value from a dropdown select