我需要知道如何检测特定div或表单中的第一个,第二个或第三个ul元素。我正在尝试做的是,一旦在页面上检测到ul
,我想更改第二个ul元素中的li
。
var ulcountfood = $('#nl-form').find('ul').length;
alert(ulcountfood);
//Change second ul li List html
答案 0 :(得分:1)
您应该尝试使用.eq()
来确定当前ul
是第一个还是第二个等等。
请参阅文档:https://api.jquery.com/eq/
因此,对于每个ul
,您需要检查其索引,
$('#nl-form').find('ul').each(function(){
if($(this).eq(0)) {
//do your first ul specific logic
} // and so on for other ul
});