0

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

3
  • 2
    $('#option_id').text('target text'); would change the option text to whatever you want, the if statements shouldn't be too hard to do Commented Aug 26, 2012 at 1:00
  • @Izzey got it, why didnt u just post it as an answer? Commented Aug 26, 2012 at 1:02
  • 1
    @NicolasBrown I'm too lazy :D Commented Aug 26, 2012 at 1:02

2 Answers 2

1

jsFiddle Example

var option = $('#sub_cat').find('option:contains("All")');
option.text('New Text');
Sign up to request clarification or add additional context in comments.

Comments

1

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");
});

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.