[英]Select ul element with same class inside ul element
How select second ul element with "dropdown-menu" class inside ul element with same class? 如何在具有相同类的ul元素中选择具有“下拉菜单”类的第二个ul元素?
<ul class=" dropdown-menu">
<li>
<ul class=" dropdown-menu">
</ul>
</li>
</ul>
If you want to select just the 2nd element, here is the workaround: 如果您只想选择第二个元素,这是解决方法:
.dropdown-menu .dropdown-menu:first-child {}
More specific version: 更具体的版本:
ul.dropdown-menu li ul.dropdown-menu:first-child {}
$('.dropdown').find('.dropdown:first').addClass('child-dropdown-menu');
Cheers! 干杯!
Here's a pure js answer I'm assuming you already have the ul reference in a variable. 这是一个纯粹的js答案,我假设您已经在变量中包含了ul引用。
var uls = ul.getElementsByTagName("ul");
var targetUl = undefined;
for(var i = 0; i < uls.length; i++){
for( var j = 0; j < uls[i].classList.length; j++){
if(uls[i].classList[j] == "dropdown-menu"){
targetUl = uls[i];
break;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.