如何得到div下面的span,有class的span,如下图代码

问题

想要得到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>
POPMUISE
浏览 615回答 4
4回答

慕斯王

$("#jie span[class]").length

幕布斯6054654

$.each($('#jie span'),function(){ var classname = $(this).attr('class'); if(classname !=null){ console.log(classname) } }); 或者console.log($("#jie span[class]"))

撒科打诨

var tempList = []; $('#jie span').each(function (){ if($(this).attr('class')){ tempList.push($(this)) } }); console.log(tempList); 或者console.log($("#jie span[class]"))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java