Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Text of a Option with jQuery

Tags:

How can I change the text of an option with jQuery?

I'd like to change Newest with Oldest in an option is a <select> element.

$('select option:contains("Newest")').changeText('Oldest'); 

.replaceWith would not work for me.

Thanks.

----Update----

If my script looks like this:

$('select option:contains("Newest")').text('Oldest'); $('select option:contains("Oldest")').text('Newest'); 

Then I'm canceling out the first script, however, that isn't what I want. I have two options one that reads "Newest" which I'd like to replace with "Oldest" and one that reads "Oldest" which I'd like to replace with "Newest". How can I accomplish that?

like image 355
henryaaron Avatar asked Feb 27 '12 01:02

henryaaron


1 Answers

You should start a new question but here's the answer:

$('select option:contains("Newest")').text('TEMPEST'); $('select option:contains("Oldest")').text('Newest'); $('select option:contains("TEMPEST")').text('Oldest'); 
like image 86
qwertymk Avatar answered Sep 16 '22 19:09

qwertymk