Nate Pet
Nate Pet

Reputation: 46222

Javascript/Jquery how to get Key from Key/Value

I have a field called City that is a drop down. It has a key value pair.

To get the value, I can simply do the following in Jquery:

    var city = $("#city").val();

How do I get the key value though?

Upvotes: 0

Views: 132

Answers (2)

Julia McGuigan
Julia McGuigan

Reputation: 644

if it's a option within a select, try .text().

Upvotes: 0

Patricia
Patricia

Reputation: 7802

so you want the text of the selected option:

$('#city').find('option:selected').text();

Upvotes: 1

Related Questions