cycling jQuery_Succinctly | Page 66

})(jQuery); Setting/getting the value attribute of a button element You can set the value attribute of a button element by passing the val() method a text string. To get the value of a button element, use the val() method again to retrieve the text. Sample: sample63.html Editing select elements jQuery makes some of the common tasks associated with editing select elements trivial. Below are some of those tasks with coded examples. // Add options to a select element at the end. $('select').append(''); // Add options to the start of a select element. $('select').prepend(''); // Replace all the options with new options. $('select').html(''); // Replace items at a certain index using the :eq() selecting filter to // select the element, and then replace it with the .replaceWith() method. $('select option:eq(1)').replaceWith(''); // Set the select elements' selected option to index 2. $('select option:eq(2)').attr('selected', 'selected'); // Remove the last option from a select element. $('select option:last').remove(); // Select an option from a select element via its // order in the wrapper set using custom filters. $('#select option:first'); 66