:contains(text)

尋找所指定的元素內文字,包含給定文本的元素。

傳回值

Array<Element>

參數

text (String) : 一個用以找的字串。

範例

找所有包含 "John" 的 div 元素。

找所有包含 "John" and "Martin" 的 div 元素。

HTML 代碼:

<div>John Resig</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<div>J. Ohn </div>

jQuery 代碼:

$("div:contains('John')")

$("div:contains('John'),div:contains('Martin')")   //找所有包含 "John" and "Martin" 的 div 元素。

結果:

[ <div>John Resig</div>, <div>Malcom John Sinclair</div> ]

arrow
arrow
    全站熱搜

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