0

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?

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.