0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

xml:lang="en"をCSSの属性セレクターに使うとき

Posted at

名前空間プレフィックス(接頭辞)付きの属性名をCSSの属性セレクターで使うときは、:\でエスケープする必要があるけど、CSSスタイルシートで使うときと、JavaScriptでセレクターを使用してDOM要素を特定するときとで書き方が異なる。

  • CSSスタイルシートで使うとき
    \でエスケープする。\が1つ
    例: p[xml\:lang="en"]
  • JavaScriptでセレクターを使用してDOM要素を特定するとき
    \\でエスケープする。\が2つ、1つ目がJavaScriptの文字列として、2つ目が属性セレクターとして
    例: document.querySelectorAll('p[xml\\:lang="en"]')

以上、MDNに丁寧な説明が書いてありました。

See the Pen Untitled by Taku Yamaguchi (@yamahige) on CodePen.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?