Dave
Dave

Reputation: 9157

How do I select all options with jQuery with a specific value and change the value?

I want to select all the select elements that have a value of "-1" and change the value to blank aka "".

I want to change all these:

<option value="-1">Select Something</option>

to this:

<option value="">Select Year</option>

I am using this code:

jQuery().ready(function() {
    $("option[value='-1']").val('');
});

... which isn't working. Any idea why?

Upvotes: 1

Views: 187

Answers (1)

Adam Rackis
Adam Rackis

Reputation: 83356

You can select options with a specific value like this:

$("option[value='-1']")

and then set a new value with the val function:

$("option[value='-1']").val('');

DEMO

Upvotes: 3

Related Questions