7

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 Answers 2

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

Comments

0

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

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

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.