Change selected value of drop down list with jQuery

Posted by Phairoh on Stack Overflow See other posts from Stack Overflow or by Phairoh
Published on 2009-01-31T19:39:01Z Indexed on 2010/03/24 4:33 UTC
Read the original article Hit count: 153

Filed under:
|
|

I have a drop down list with known values. What I'm trying to do is set the drop down list to a particular value that I know exists using jQuery. Using regular JavaScript, I would do something like:

ddl = document.getElementById("ID of element goes here");
ddl.value = 2; // 2 being the value I want to set it to.

However, I need to do this with jQuery because I'm using a CSS class for my selector (stupid ASP.NET client ids...).

Here are a few things I've tried:

$("._statusDDL").val(2); // doesn't find 2 as a value
$("._statusDDL").children("option").val(2) // also failed.

How can I do it with jQuery?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript