Get value of HTML select option using its index with jQuery [closed]

一曲冷凌霜 提交于 2019-12-03 10:08:54
$('.dropdown option').eq(1).val()

eq() will start with 0 as it is an index

Get the currently selected value with

$('.dropdown option:selected').val()

use text() instead of val() to retrieve the text content

To get the text:

var list = document.getElementById("dropdown");
var value = list.options[1].text;

You can use this to get the value:

$('select.dropdown option').eq(1).val();

An this to get the text:

$('select.dropdown option').eq(1).text();

Demo here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!