Getting selected picklist text using jQuery when I already have the selected object

Here is a simple, real question for beginners:

I know that you can get the selection text, for example,

$('#selectBoxId option:selected').val(); 

But what if I already have a select object in my hand?

eg.

 var select = $('#selectBoxId'); 

What will happen next? Is this the right way?

 select.find('option:selected').val(); 
+6
source share
1 answer

Just select.val(); enough. It will give you the selected value .

Job demonstration

If you want to select the text option, then you need to do

 select.find('option:selected').text(); 

or

 select.find('option:selected').html(); 
+13
source

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


All Articles