diff options
author | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2022-03-02 22:49:44 +0900 |
---|---|---|
committer | Masahiro FUJIMOTO <mfujimot@gmail.com> | 2022-03-10 22:56:58 +0900 |
commit | 5fab0a1eb99e87aa141adb3777d92c69437ae971 (patch) | |
tree | 2fe51f82c78e01e7b576a7844f866388edd64d27 /files/ja/web/api/element/getattribute/index.html | |
parent | 293c1892610700eb7f7eba45c8b264d9efc90c9b (diff) | |
download | translated-content-5fab0a1eb99e87aa141adb3777d92c69437ae971.tar.gz translated-content-5fab0a1eb99e87aa141adb3777d92c69437ae971.tar.bz2 translated-content-5fab0a1eb99e87aa141adb3777d92c69437ae971.zip |
Element 以下の a-g で始まるプロパティを移行
Diffstat (limited to 'files/ja/web/api/element/getattribute/index.html')
-rw-r--r-- | files/ja/web/api/element/getattribute/index.html | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/files/ja/web/api/element/getattribute/index.html b/files/ja/web/api/element/getattribute/index.html deleted file mode 100644 index 4ee84122ba..0000000000 --- a/files/ja/web/api/element/getattribute/index.html +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: Element.getAttribute() -slug: Web/API/Element/getAttribute -tags: - - API - - DOM - - Element - - Method - - Reference - - メソッド -translation_of: Web/API/Element/getAttribute ---- -<div>{{APIRef("DOM")}}</div> - -<p><span class="seoSummary"><strong><code>getAttribute()</code></strong> は {{domxref("Element")}} インターフェイスのメソッドで、要素の指定された属性の値を返します。</span>指定された属性が存在しない場合、値は <code>null</code> か <code>""</code> (空文字列) のどちらかになります。詳しくは<a href="#Non-existing_attributes">属性が存在しない場合</a>を参照してください。</p> - -<h2 id="Syntax" name="Syntax">構文</h2> - -<pre class="syntaxbox">let <var>attribute</var> = <var>element</var>.getAttribute(<var>attributeName</var>); -</pre> - -<p>ここで、</p> - -<ul> - <li><code><var>attribute</var></code> は <code><var>attributeName</var></code> の値を持つ文字列です。</li> - <li><code><var>attributeName</var></code> は値を取得したい属性の名前です。</li> -</ul> - -<h2 id="Examples" name="Examples">例</h2> - -<pre class="brush:js">const div1 = document.getElementById('div1'); -const align = div1.getAttribute('align'); - -alert(align); // id="div1" の要素の align の値を表示します。</pre> - -<h2 id="Description" name="Description">解説</h2> - -<h3 id="Lower_casing" name="Lower_casing">小文字化</h3> - -<p>HTML 文書である DOM の HTML 要素に対して呼び出すと、 <code>getAttribute()</code> は処理前に引数を小文字化します。</p> - -<h3 id="Non-existing_attributes" name="Non-existing_attributes">属性が存在しない場合</h3> - -<p>基本的にはすべてのウェブブラウザー (限定的なリストですが Firefox, Internet Explorer, Opera の最新バージョン, Safari, Konqueror, iCab など) は、指定された要素に指定された属性が存在しない場合は <code>null</code> を返します。これは<a href="http://dom.spec.whatwg.org/#dom-element-getattribute">現在の DOM 仕様書の草稿</a>で指定されています。一方、古い DOM 3 Core 仕様書では、このような場合の正しい返値は実際には<em>空文字列</em>となっています。そしていくつかの DOM の実装はこの動作を実装しています。実際、 <code>getAttribute()</code> の XUL (Gecko) での実装では、 DOM 3 Core 仕様書に従い空文字列を返します。結果的に、指定された要素に指定された属性が存在しない可能性があるのであれば、 {{domxref("element.hasAttribute()")}} を使用して属性の存在をチェックしてから <code>getAttribute()</code> を呼び出すべきでしょう。</p> - -<h3 id="Retrieving_nonce_values" name="Retrieving_nonce_values">ノンス値の受け取り</h3> - -<p>セキュリティ上の理由で、スクリプト以外、例えば CSS セレクターから来た <a href="/ja/docs/Web/HTTP/CSP">CSP</a> のノンスと、 <code>.getAttribute("nonce")</code> の呼び出しは隠蔽されます。</p> - -<pre class="brush: js example-bad">let nonce = script.getAttribute('nonce'); -// 空文字列が返される -</pre> - -<p>コンテンツ属性のノンスをるには、代わりに <code><a href="/ja/docs/Web/API/HTMLOrForeignElement/nonce">nonce</a></code> プロパティを使用してください。</p> - -<pre class="brush: js">let nonce = script.nonce;</pre> - -<h2 id="Specifications" name="Specifications">仕様書</h2> - -<table class="standard-table"> - <thead> - <tr> - <th scope="col">仕様書</th> - <th scope="col">状態</th> - <th scope="col">備考</th> - </tr> - </thead> - <tbody> - <tr> - <td>{{SpecName('DOM WHATWG', '#dom-element-attachshadow', 'attachShadow()')}}</td> - <td>{{Spec2('DOM WHATWG')}}</td> - <td></td> - </tr> - </tbody> -</table> - -<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> - -<div> -<p>{{Compat("api.Element.getAttribute")}}</p> -</div> |