How To Select Text and Value from Drop Down List in jQuery
This post is a very simple tip for getting the selected text and selected value from a drop down list using jQuery. A very common usage and we use it in almost every project that we do. To start with, let us consider we have a drop-down list with ID “numbers”. The DOM structure of the select list something looks like below.
To get the selected text and value for this drop down list, we can use the below piece of code.
var text = $("#numbers option:selected").text(); var value = $("#numbers option:selected").val(); alert("Selected text=" + text + " Selected value= " + value);
Keep learning and sharing!