From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/element/hasattribute/index.html | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 files/ja/web/api/element/hasattribute/index.html (limited to 'files/ja/web/api/element/hasattribute/index.html') diff --git a/files/ja/web/api/element/hasattribute/index.html b/files/ja/web/api/element/hasattribute/index.html new file mode 100644 index 0000000000..1999a7a802 --- /dev/null +++ b/files/ja/web/api/element/hasattribute/index.html @@ -0,0 +1,49 @@ +--- +title: element.hasAttribute +slug: Web/API/Element/hasAttribute +tags: + - DOM + - DOM Element Methods + - Gecko +translation_of: Web/API/Element/hasAttribute +--- +
{{ApiRef}}
+ +

概要

+ +

hasAttribute

+ +

は指定の要素が指定の属性を持つか否かを示す真偽値を返します。

+ +

 

+ +

構文

+ +
var result = element.hasAttribute(attName);
+
+ + + +

+ +

対象属性の存在をチェックし、無い場合にのみ属性を設定する例を以下に示します。

+ +
var d = document.getElementById("div1"); // 対象要素を取得
+
+if ( !d.hasAttribute("align") ) {
+  d.setAttribute("align", "center");
+}
+ +

注記

+ +
{{DOMAttributeMethods}}
+ +

仕様書

+ + -- cgit v1.2.3-54-g00ecf