:lang()
:langはlang属性から要素を絞り込めるセレクタです。
属性セレクタとの違いは、-(ハイフン)区切りの言語指定がある場合にハイフンの前の文字列でも判定が行える点です。
次のようなHTMLがあったとします。
<style>
.ja{
color:red;
}
.en{
color: blue;
}
.en-us{
color: green;
}
</style>
<div lang="ja">ja</div>
<div lang="en">en</div>
<div lang="en-es">en-es</div>
<div lang="en-us">en-us</div>
次のスクリプトを実行することでjaは赤色に、enとen-esは青色に、en-usは緑色になります。
$(":lang(ja)").addClass("ja");
$(":lang(en)").addClass("en");
$(":lang(en-us)").addClass("en-us");
jQuery 1.9.0での追加/変更:langはCSS3で定義されているセレクタのためCSS3対応ブラウザでは古いバージョンのjQueryから利用できますが、jQuery 1.9.0でjQueryのSizzleエンジンに追加されCSS3未対応ブラウザでも利用可能になりました。
参考URL
:lang Selector | jQuery API Documentation
登録日 : 2013年01月19日 最終更新日 : 2013年1月19日
同じカテゴリー(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セレクタ
- 要素セレクタ
- ユニバーサルセレクタ