Julian Dormon
Julian Dormon

Reputation: 1779

How to set the selected option of a select list by value NOT by selectedIndex using jQuery?

I am trying to set the selected item of a select which equals a certain value. I am currently using:

$("#mySelectList").val(4);

This however is setting the list to the 4th selectedIndex instead of the selectedIndex which has a value of 4.

I am using version 1.9.1. Thanks for your help!

Upvotes: 0

Views: 233

Answers (1)

palaѕн
palaѕн

Reputation: 73896

Try this:

$("#mySelectList option[value='4']").prop('selected', true);

Upvotes: 3

Related Questions