Get the value and text of SELECT in jQuery


Possible Duplicate:
Getting the value of the selected option tag in a select box

For a SELECT box, how do I get the value and text of the selected item in jQuery?

For example,

<option value="value">text</option>

<select id="ddlViewBy">
    <option value="value">text</option>


var txt = $("#ddlViewBy option:selected").text();
var val = $("#ddlViewBy option:selected").val();

JS Fiddle DEMO