如何找到没有id,名称,类,属性等的元素?

irr*_*nal 4 javascript jquery

我想找(可能是使用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)

Pla*_*dea 5

感谢@adeneo获取信息,this.attributes始终返回一个值.因此,我会清理答案.

如何使用jQuery选择"裸"(没有任何属性)的元素:

$('span').filter(function(){
    return (this.attributes.length === 0);
}).text();
Run Code Online (Sandbox Code Playgroud)

.text()方法只是一个占位符,此时可以应用任何内容.

怎么了,这是一个简单的jsFiddle.