:has()
hasセレクタは特定の要素を持った要素を検索できるセレクタです。
次のようなHTMLがあったとします。
<div><p>Hello in a paragraph</p></div>
<div>Hello again! (with no paragraph)</div>
次のセレクタではp要素を内包する最初のdiv要素を含むjQueryオブジェクトを返します。
$("div:has(p)")
このセレクタはCSSのセレクタにはなくjQueryの独自のセレクタです。パフォーマンスを考慮する場合はhasメソッドを利用するほうがよいでしょう。
参考URL
登録日 : 2012年10月24日 最終更新日 : 2012年10月24日
同じカテゴリー(Selectors)のエントリー
- :disabled
- [attribute~=’value’]
- [attribute|=’value’]
- :animated
- :focus
- :target
- :lang()
- :root
- :only-of-type
- :last-of-type
- :first-of-type
- :nth-last-of-type()
- :nth-of-type()
- :nth-last-child()
- :selected
- :checked
- :file
- :button
- :reset
- :image
- :submit
- :checkbox
- :radio
- :password
- :text
- :input
- :parent
- :has()
- :contains()
- :header
- :lt()
- :gt()
- :eq()
- :odd
- :even
- :last
- :first
- [attributeFilter1][attributeFilter2]
- [attribute*=’value’]
- [attribute$=’value’]
- [attribute^=’value’]
- [attribute!=’value’]
- [attribute=’value’]
- [attribute]
- :not()
- :empty
- :only-child
- :last-child
- :first-child
- 兄弟セレクタ
- 隣接セレクタ
- 子セレクタ
- 子孫セレクタ
- グループセレクタ
- classセレクタ
- idセレクタ
- 要素セレクタ
- ユニバーサルセレクタ