问题
想要得到div下面的拥有class属性的span,不管理class是什么 有多少个
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="jie">
<span>sdfds</span>
<span class="try try21">sdfds</span>
<span>sdfds</span>
<span class="try2 try22">sdfds</span>
<span>sdfds</span>
<span class="try3 ">sdfds</span>
<span class="try4 sdfsd44">sdfds</span>
</div>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script>
console.log($("#jie span").hasClass());
</script>
</body>
</html>
4 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
$.each($('#jie span'),function(){
var classname = $(this).attr('class');
if(classname !=null){
console.log(classname)
}
});
或者console.log($("#jie span[class]"))
撒科打诨
TA贡献1934条经验 获得超2个赞
var tempList = [];
$('#jie span').each(function (){
if($(this).attr('class')){
tempList.push($(this))
}
});
console.log(tempList);
或者console.log($("#jie span[class]"))
添加回答
举报
0/150
提交
取消