2

I have Html drop down. i want to mark "11:00 pm" as selected using jquery in single line how can i do it ?

<select name="timing" id="timing" >
      <option value="00:00 am">Midnight</option>
      <option value="11:00 pm">11 pm</option>
      <option value="10:00 pm">10 pm</option>
      <option value="09:00 pm">9 pm</option>
      <option value="08:00 pm">8 pm</option>
    </select>

3 Answers 3

7

You can use

$('#timing').val('11:00 pm');
Sign up to request clarification or add additional context in comments.

Comments

2
$('option[value="11:00 pm"]').attr('selected', 'selected');

Comments

1
var source = $("#option");
var v="10:00 pm";
source.val(v);
source.change();

1 Comment

This would only work, if there is an element with the id-attribute set to option. This is not the case in his example-code.

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.