Change elements of a select

0

I have a select with options where some names come out in English. I'm trying to go through it and change it using JQuery. But I can not do it ... Some help

var length = $('select[name=day]').children('option').length;
for (i=0; i<length; i++){
    $("select[name=day]").val(i).change("Lunes");            
}
<select name="day">
	<option value="" selected>Select</option>
	<option value="monday">Monday</option>
	<option value="tuesday">Tuesday</option>
	<option value="friday">Friday</option>
</select>
    
asked by Eduardo 18.02.2018 в 21:30
source

2 answers

0

You could get the options of the select in the selector and go through them each one. To change the text, use the function text() and in case you want to change the value use the function val()

  $('select[name=day] > option').each(function(index, element){
      $(element).text('lunes');
  });

Greetings

    
answered by 18.02.2018 в 22:05
0

You can use the each () method of jQuery :

var $options = $('select[name=day]').children('option');
   
$options.each(function(){
    $(this).text("lunes");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="day">
	<option value="" selected>Select</option>
	<option value="monday">Monday</option>
	<option value="tuesday">Tuesday</option>
	<option value="friday">Friday</option>
</select>
    
answered by 18.02.2018 в 22:08