Get value of nth item in an un-ordered list
For this code,
<ul id="date-list" hidden="hidden">
<% foreach (string item in (List<string>)Model.OpenCloseTime)
{%>
<li value="<%= item %>"><%= item %></li>
<% }%>
</ul>
How could i get the value of nth item in the list. It is an MVC project and we are using jquery. 开发者_如何学编程 Basically I am trying to use the string value as a min max time for an input of type="time".
Thanks!
var found = $('#date-list').find('li').eq(n).text()
$('#date-list').children().eq(n).attr('value');
However, if you want a custom data attribute, html5 states you should precede it with data-
<li data-value="<%= item %>"><%= item %></li>
$('#date-list').children().eq(n).data('value');
Here you go:
$( '#date-list' ).children().eq( n ).text()
$('#date-list>li:nth-child('+n+')'.attr('value');
精彩评论