首頁  >  選擇器  > [attribute]

返回值:Array<Element(s)> [attribute]

概述

匹配包含給定屬性的元素。注意,在jQuery 1.3中,前導的@符號已經被廢除!如果想要相容最新版本,只需要簡單去掉@符號即可。

參數

attribute String V1.0

屬性名

示例

描述:

查詢所有含有 id 屬性的 div 元素

HTML 程式碼:

<div>
  <p>Hello!</p>
</div>
<div id="test2"></div>
jQuery 程式碼:

$("div[id]")
結果:

[ <div id="test2"></div> ]