How to obtain the latest option?

April 19th 20 at 12:48
2 answers
April 19th 20 at 12:50
Solution
You actually correctly received, use the option you want.
https://jsfiddle.net/L53714wk/
@nikki65, right?
I just have it selected not stanovit
although I did write option.selected = true; - rupert11 commented on April 19th 20 at 12:53
@rupert11, well, you to select is addressed, and the need to appeal to children, to all that is inside.
document.querySelectorAll('#select option'); - nikki65 commented on April 19th 20 at 12:56
@nikki65, thank you
I'm sorry
why is there undefined - https://jsfiddle.net/tnhrzy2k/2/ - rupert11 commented on April 19th 20 at 12:59
@nikki65, Getting selected option - rupert11 commented on April 19th 20 at 13:02
@rupert11, https://jsfiddle.net/1nzm4Lcb/ - nikki65 commented on April 19th 20 at 13:05
@nikki65, thank you
just on one site I saw it(
5e9c1dcbca91c136075598.jpeg - rupert11 commented on April 19th 20 at 13:08
April 19th 20 at 12:52
Solution
Even as options

document.querySelector('#select option:last-child").selected = true;

or
document.querySelector('#select').options].pop().selected = true;

or
Array. from(document.querySelectorAll( select option’)).slice(-1)[@].selected = true;

Find more questions by tags JavaScript