I have a jquery dropdown which looks as follows after inspecting it in DOM explorer.
<select name="cityID" id="ddlCity" style="width: 128px; display:none;" data-val="true" data-val-number="ID must be a number">
<option value = "0">Select city</option>
<option value = "1234">New York</option>
<input id="txt_ddlCity" style="width: 100px;" autocomplete="off"></input>
</select>
I want to set the value of this dropdown to 'New York' by using index.
I tried
$("select#ddlCity").prop('selectedIndex', 1);
However, the value is not getting selected in dropdown.
I also tried to set using value as $("#ddlCity").val(1234);
but it also doesn't work.
Can anyone figure out what I am doing wrong here. any help would be greatly appreciated.
Update:
This is not the duplicate of mentioned question. None of the answer is working for my case. Also please note it contains inside tag. Not sure if it is making any issue