Change the Text of a Option with jQuery Change the Text of a Option with jQuery javascript javascript

Change the Text of a Option with jQuery


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');


$('select option:contains("Newest")').each(function(){   var $this = $(this);   $this.text($this.text().replace("Newest","Oldest"));    });​

http://jsfiddle.net/eSa5p/

EDIT: Answer to the new question:

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

http://jsfiddle.net/eSa5p/3/


$("#mySelect option").html(function(i,str){  return str.replace(/Newest|Oldest/g,  // here give words to replace     function(m,n){         return (m == "Newest")?"Oldest":"Newest";  // here give replacement words     });});

demo : http://jsfiddle.net/diode/eSa5p/2/