$('# select option: last '); $('# select option: eq( 3)'); $('# select option: gt( 5)'); $('# select option: lt( 3)'); $('# select option: not(: selected)'); // Get the text of the selected option( s), this will return the text of // all options that are selected when dealing with a muli-select element. $(' select option: selected '). text(); // Get the value attribute value of an option in a select element. $(' select option: last '). val(); // Getting the: last option element. // Get the index( 0 index) of the selected option. // Note: Does not work with multi-select elements. $(' select option '). index($(' select option: selected ')); // Insert an option after a particular position. $(' select option: eq( 1)'). after('< option value =""> option </ option >'); // Insert an option before a particular position. $(' select option: eq( 3)'). before('< option value =""> option </ option >');
Selecting form elements by type
It is possible to select form elements by their type— e. g. $(' input: checkbox '). jQuery provides the following form type filters for selecting form elements by their type.
� � � � � � � � �
: text: password: radio: checkbox: submit: image: reset: file: button
Selecting all form elements
You can select all form elements by using the: input form filter. This filter will select more than just input elements, it will select any < textarea >, < select >, or < button > elements as well. In the coded example below, take notice of the length of the wrapper set when using the: input filter.
Sample: sample64. html
<! DOCTYPE html > < html lang =" en ">
67