IMG-LOGO

How to get selected option text and value in JQuery?

andy - 19 Oct, 2019 2413 Views 0 Comment

In this article, we are going to learn how to get the selected option text and value in JQuery.

Let's say we have the following select dropdown html code.

<select id="cboFruit" class="comboBox">
	<option value="">Select Fruit</option>
	<option value="Apple">Apple</option>
	<option value="Banana">Banana</option>
	<option value="Blueberry">Blueberry</option>
	<option value="Melon">Melon</option>
	<option value="Watermelon">Watermelon</option>
</select>

To get the selected text, we can use the following JQuery code. The hashtag # represents the selector id of select HTML object.

$("#cboFruit option:selected").text();

To get the selected value, we can use the built in val method.

$("#cboFruit").val();

Demo

You can see the following real demo by clicking the Get Value button to get the select option value or click the Get Text button to get selected option text value.

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

Become a jquery expert in just 10 minutes.

Completely new to JQuery script Don t worry you are not alone We have summarize a list of tips for newbie to learn JQuery faster The best way to strength your JQuery skills is by testing our tips directly in ...