我想找(可能是使用jquery)一个空/裸/等的元素.例如,我想找到所有没有id,name,class或任何其他属性的span元素.
<html>
<head></head>
<body>
<span> found </span>
<span id="foo"> not found </span>
<span name="foo"> not found </span>
<span class="foo"> not found </span>
<span style="width:foo"> not found </span>
<span> found </span>
<span foo="bar"> not found </span>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
感谢@adeneo获取信息,this.attributes始终返回一个值.因此,我会清理答案.
如何使用jQuery选择"裸"(没有任何属性)的元素:
$('span').filter(function(){
return (this.attributes.length === 0);
}).text();
Run Code Online (Sandbox Code Playgroud)
该.text()方法只是一个占位符,此时可以应用任何内容.
| 归档时间: |
|
| 查看次数: |
131 次 |
| 最近记录: |