tags:

views:

91

answers:

2

I am trying to update the text of one of the options on a select dropdown after an action on my page. Does anyone know how to do this in jquery? I have tried this:

$("#selectid").text("newtext"); 

But that will remove all of the other options in the select list and it makes it blank. I know this is not the right approach because I just want to update one of the option values. Thanks for the help

+2  A: 
$('#selectid option:eq(NUMERIC_INDEX_GOES_HERE)').text('newtext');

or

$('#selectid').find('option[value="OPTION_VALUE"]').text('newtext');

or

$('#selectid option').filter('[value="OPTION_VALUE"]').text('newtext');

or

$('#selectid option:contains("OLD_TEXT_VALUE")').text('newtext');
cballou
awesome this worked perfectly!
Jquery_quest
A: 

And to change the option's value, you can of course use:

$('#selectid option:eq(NUMERIC_INDEX_GOES_HERE)').val('new value goes here');
JK