I have the following HTML:
<select name="1028071" class="LC" id="1028071" style="width: 100%;">
<option selected="selected" value="-1">[Please select a value]</option>
<option value="10604534" data-uid="154b2706-505e-401c-a066-a37a1889e3be">[Other]</option>
<option value="10604535" data-uid="25070b3b-8215-440b-b3cf-c6cf52f01efc">Reason 1</option>
<option value="10604536" data-uid="fd3394ea-a7e8-45e8-8385-71dee98238ff">Reason 2</option>
</select>
I am trying to pre-select [Other]. Both value and the text are variables. The only fixed value across environments is the data-uid.
I tried the following but it is not working:
var other = $(formalRequestReasonFieldId).find("option").filter(function() {
return $(this).data('uid') == '154b2706-505e-401c-a066-a37a1889e3be';
});
alert(other.text()); // returns blank text
other.attr('selected', true); // does not work, no errors
$('option[data-uid="154b2706-505e-401c-a066-a37a1889e3be"]')uidyou're searching for is what you expect it to be?uidvalue using thedataapi