Using jQuery what is the best way of editing option text for a given select value.
I know the value of the option I want to edit. I thought it would be something like...
$('#select').val().$('option').html('New Text');
But I am clearly missing something.
Something like this?
Have a look at Selectors for more information on selecting the correct item. You could do something like
Or you can use
If you know the value.
This one help you to get the options value,
And you can set default selected value by using
prop()
function. Take an example here.could use
.html
instead of.text
, if adding html content.You're probably looking for the :selected selector and the text() method: