get attribute of selected option jquery

As you know, name isn't a valid attribute of an option element, you can use a data parameter, like this: The jQuery attr() method is used to get or set attributes and values of the selected html elements. - To get the attribute value of an element with jQuery, it is used attr() function. jquery get data attribute of selected option . Syntax: . Get Attribute Using jQuery attr () Method If you want to perform some event but access an HTML element with its attribute, you can do so with jQuery attr (). Here you can see that two type of get data attribute methods are :- You can use jQuery .prop() method to enable or disable a select dropdown list, dynamically at runtime. The name of the attribute to get. You can also get select option attribute values with the help of JQuery for that use below code. Please give us a attr ('data-val'); … Source: stackoverflow.com. You will get the value of the selected option in the alert message box. 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. You can try to run the following code to implement how to get the value of custom attribute… The HTML