How to preselect option in select box using jQuery

John picture John · Jun 24, 2010 · Viewed 42.6k times · Source

I have one select box with various options.

When a page loads then one option with a value, for example 10, should be preselected with jQuery.

How can I do that?

Answer

Adam picture Adam · Jun 24, 2010

When the page loads run this (you can put it in <body onload="//put code here">):

$("option[value='10']").attr('selected','selected');