Claudio Delgado
Claudio Delgado

Reputation: 2349

How to change input option text with jQuery?

I want to target this input and change it dynamically with jQuery:

<select id="sub_cat" style="" name="sub_cat">
<option selected="selected" value="-10">All</option>

I want to be able to change 'All' with an if statement based on different variables. Is this possible with jQuery? And how? Any help is appreciated. Thanks

Upvotes: 0

Views: 90

Answers (2)

Peter Olson
Peter Olson

Reputation: 142947

This will change the value of the selected option depending on the value of a lang variable.

$("#sub_cat option").each(function() {
  var option = $(this);
  var val = option.val();
  if(val === "All") option.val("Hepsi");
});

Upvotes: 1

Gabe
Gabe

Reputation: 50503

jsFiddle Example

var option = $('#sub_cat').find('option:contains("All")');
option.text('New Text');

Upvotes: 1

Related Questions