The following code will get the text value of the selected option using jQuery. All these actions can be performed using the attr(), and removeAttr() jQuery methods. - To get the attribute value of an element with jQuery, it is used attr() function. jQuery attr() Method. You have a select element, and you need to “select” one of its options based on one of its values. To get selected option value , we can implement some jQuery codes on select option field. Copyright © 2021 Tutorial Republic. ), apply this syntax: $('element').attr('attribute_name', 'attribute_value'); Examples: - Add the attribute id="value" to the clicked DIV: jQuery provides two methods to get the value of the selected option from the select box. CTRL + SPACE for auto-complete. HTML select option field is a drop down list of options, user may be allowed to choose one or more option(s) from this list. How to get and set data attribute values. Answer: Use the jQuery :selected Selector. Please give us a jquery get data attribute of selected option . To achieve the best performance when using :selected to select elements, first select the elements using a pure CSS selector, then use .filter(":selected"). However, simply using the $.text will return the whole text of the select dropdown. See demo for more options. We will also see various operations that can be performed over it with the below given examples. Answer: Use the CSS Attribute Selector. Is this website helpful to you? How to get attribute from selected option using jQuery, How to create text editor in textarea using jquery, How to converting pacific time string to time format in PHP, Restrict characters in input field using javascript, Read text file draw line between two points google map API using javascript, Pick up Location and Drop Location line draw in google map API using javascript, How to Subscribe to List using MailChimp API using PHP, How to Create Dynamic Excel File Using PHPExcel Library in Codeigniter, How to create flash messages in Codeigniter. You can enable multiple section in a select box by adding the attribute multiple to the