没有任何属性的元素的jQuery选择器 [英] JQuery selector for an element without any attribute

查看:85
本文介绍了没有任何属性的元素的jQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择一个/所有不具有任何关联属性的元素.是否有任何方法可以选择特定元素而无需考虑其他段落标签包含哪些属性?

I want to select an/all element which doesn't have any attribute associated with it.is there any way to select particular element without considering what attributes other paragraphs tags contain?

例如:

<p class="a" id="para1">This is paragraph 1</p>
<p id="para2" class="a b c d e f" >This is paragraph 2</p>
......
......
<p>This is paragraph 3</p> <!-- select this p without attribute -->
<div>
  <p class="inside-div" id="para5">This is paragraph</p>
</div> <!-- select this div without attribute-->

推荐答案

要获取所有没有属性的元素,请使用选择器body>*以及属性过滤器(否则将获得html/head/title等)

To get all elements without attributes, use selector body>* along with the attributes filter (otherwise you get html/head/title etc)

$("body>*").filter(function() { 
    return this.attributes.length === 0; 
})

简单的在这里进行操作,并带有html

Simple fiddle here with OPs html

这篇关于没有任何属性的元素的jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆