If I'm understanding, you have two options with the same value. You want to select specifically the one with id-criteria=1 and value=1.
$('.criteria') .children() //Get all options .removeAttr("selected") //Remove their 'selected' attribute .end() //Refer back to <select> .children('option[id-criteria="1"][value="1"]') //Find option .attr("selected",true); //Select it
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select class="criteria"> <option selected>Example</option> <option>Another Example</option> <option id-criteria="1" value="1">Criteria: 1, Value: 1</option> <option id-criteria="2" value="1">Criteria: 2, Value: 1</option> </select>
For anyone curious as to why I've chosen to deselect the previous values, it's mostly for consistency in attribute-based selections. For example, if you had CSS to style the selected element of this dropdown, not removing the selected attribute would cause multiple elements to appear selected.
$('.criteria') .children('option[id-criteria="1"][value="1"]') //Find option .attr("selected",true); //Select it
option[selected] { color: red; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select class="criteria"> <option selected>Example</option> <option id-criteria="1" value="1">Criteria: 1, Value: 1</option> </select>
.val()updates the value property and that element's value is already 1. Are you trying to change the value of theid-criteriaattribute that you created instead?.val(), it selects the value of the specified element.id-criteriais an invalid HTML5 attribute. Usedata-id-criteriainstead.