How to get value from dropdown in jQuery

I have a drop-down list on my webpage, how can I get the value from the selected option from them

as

<select id="selme"> <option id="a" value="1">I need it</option> </select> 

how can I get the value "I need" when he chooses.

I'm not talking about the value attribute. I need a value that populates the dropdownlist option tags

+4
source share
6 answers

Try

 $("#selme").change(function(){ $(this).find("option:selected").text(); }); 

See working demo

+6
source

Here is jsfiddle for you. I just did http://jsfiddle.net/AqmZp/

This is basically just $ ("# selme"). val ();

0
source

Try it.

$('#selme option:selected').text();

0
source
 $('#selme option:selected').html() 
0
source

Check it out →

To receive text

 $("#selme").change(function(){ $(this[this.selectedIndex]).text(); }); 

To get the value

 $("#selme").change(function(){ $(this[this.selectedIndex]).val(); }); 
0
source

Source: https://habr.com/ru/post/1336770/


All Articles