Liron Harel
Liron Harel

Reputation: 11247

Set selected option by option's attribute value

I have a HTML Select element with various options. Each option has an attribute called label.

How can I set option as selected by this attribute value?

Upvotes: 0

Views: 34

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075587

You can look up the option using an attribute equals selector, then set its selected property to true using prop.

$('option[label="the value here"]').prop("selected", true);

Upvotes: 3

Related Questions