javascript - jQuery set focus on selected item of a select list -


i have select list size="10" - shows 10 of 100 options available.

when page loads, 1st 10 options displayed, if option value 50 selected.

i have read adding focus selected item of select list work when page loads option 50 displayed in select list, instead of 1st 10 options.

however, after reading many threads , searching google, unable work out how set focus selected item.

i wanting set both selected , focus applied item of select list.

here have tried , not work:

$('#id_preview_style_select option:selected').prop('selected', true);  //set selected value.  $('#id_preview_style_select option:selected').prop('focus', true);  //does not work. $('#id_preview_style_select option:selected').focus();  //does not work 

this seeking achieve:

<select id="id_preview_style_select" size="10" autofocus>   <option value="0">style 0</option>   <option value="1">style 1</option>   <option value="2">style 2</option>   <option value="3">style 3</option>   ....   <option value="50" selected focus>style 50</option>   ....   <option value="99">style 99</option>   <option value="100">style 100</option> </select> 

any assistance appreciated.

.prop('focus', true); never work since focus() method, not property (need invoked).

try $('#id_preview_style_select option:selected').focus();

if doesn't work right away might need timeout timeout of 0 milliseconds. help.

edit: if none of works (it might browsers not allow this) i'd scroll list of options, user can see selected.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -