-2

hello I have a select after having made the choice I would like with a button to put it back to o I want to use a class and not an ID I tried the code below but it doesn't work

<script>
$( "#reset" ).click(function() {
  //alert( "Handler for .click() called." );
  $('over').val(0);
});
</script>
<select class="over"  name="overtimeh">
<option value="2.75">2.75</option>
<option value="0">0</option>
<option value="0.25">0.25</option>
<option value="0.5">0.5</option>
</select>

<input type="button" id="reset" value="reset"></input>

ariane
  • 29
  • 4
  • 2
    Typo. `over` is a type selector. You forgot the `.` at the front to make it a class selector. – Quentin Feb 23 '23 at 09:42
  • 2
    Oh. You have a second problem. [Here is the duplicate for it](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element). – Quentin Feb 23 '23 at 09:43

1 Answers1

-1

You can manage the "selected" value:

    $(document).ready(function() {
        $( "#reset" ).click(function() {
           $('option[value="0"]').prop('selected', true);
        });
    });

EDIT: Or you could also fix your typo

$('over').val(0);  //wrong
$('.over').val(0); //right

code answer with working example on JSfiddle

Sparvhok
  • 54
  • 3