close

#id

根據給定的元素ID做為選擇的條件。
如果選擇器中包含特殊字串,可以用兩個斜線轉義。參考範例。

Matches a single element with the given id attribute.

傳回值

Element

參數

id (String) : 用於搜尋透過元素 id 中屬性的值。

範例

尋找 ID 為"myDiv"的元素。

HTML 代碼:

<div id="notMe"><p>id="notMe"</p></div>
<div id="myDiv">id="myDiv"</div>

jQuery 代碼:

$("#myDiv");

結果:

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

尋找含有特殊字串的元素

HTML 代碼:

<span id="foo:bar"></span>
<span id="foo[bar]"></span>
<span id="foo.bar"></span>

jQuery 代碼:

#foo\\:bar
#foo\\[bar\\]
#foo\\.bar

arrow
arrow
    全站熱搜

    mitblog 發表在 痞客邦 留言(0) 人氣()