dubbs dubbs - 23 days ago 4
HTML Question

Chaning the select option value by jQuery

I have a select html form element with a range of option values as per below.

<select name="budget" id="budget" class="selectInput required">
<option value="" selected>Select an option...</option>
<option value="£5-£10K">£5-£10K</option>
<option value="£5-£10K">£10-£15K</option>

I would like to be able to change the value of these options in jQuery - how can I do this??? I thought this would work - but it doesnt seem too?

$("#budget option[value='£5-£10K']").val('Monkeys');

e.g. changing the value of the option that had '£5-£10k' to become 'Monkeys'

Any ideas?


Wex Wex

An option element has two key properties - value and text. You're changing one but not the other:

$("#budget option[value='£5-£10K']").val('Monkeys').text('Monkeys');