0

I just basically want to change the first value of "Select" to more meaningful, as in "Select Category". This needs to be done through JQuery.

Here is the HTML

<select data-facet="field" id="ajax-facets" name="field_" class="form-select processed">
      <option value="0">Select</option>
      <option value="Do Something">Do Something</option>
      <option value="Did Something">Did Something</option>
</select>

How can I do it through JQuery?

1

4 Answers 4

2

To change the Text:

$('option[value=0]').text('Select Category')

To change the value:

$('option[value=0]').val('Select Category')

To change both of them, before (the page complete to load)

$(function(){
    $('option[value=0]').text('Select Category').val('Select Category')
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Any way, I can do it when this select changes?
1
$('#ajax-facets option:first').attr('value','meaningful');

or

$('#ajax-facets option[value=0]').attr('value','meaningful');

Comments

1

This is very simple:

$(function(){
    $("#ajax-facets option:first").text("Select Category");
});

Updated fiddle

Comments

1

I assume you want to change the text of the first <option>.

$('option[value="0"]').text('Select Category');

However, I'm not sure why you need to do this with jQuery. The problem is a little bit unclear to me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.