「JavaScript」hasAttributeNS関数で属性があるかどうか判定する

2020年10月20日

説明
hasAttributeNS は現在の要素が指定した属性を所有するか否かを示す boolean 値を返します。
構文
result =element.hasAttributeNS(namespace,localName)
パラメータ
result:true もしくは false
namespace:属性の名前空間を特定する文字列です。
localName:属性の名前です。
JavaScriptコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var cft = document.getElementById("divSample");
if (cft.hasAttributeNS(
"xxx/specialspace/",
"special-align")) {
cft.setAttribute("align", "right");
}
var cft = document.getElementById("divSample"); if (cft.hasAttributeNS( "xxx/specialspace/", "special-align")) { cft.setAttribute("align", "right"); }
var cft = document.getElementById("divSample"); 
if (cft.hasAttributeNS( 
        "xxx/specialspace/", 
        "special-align")) {
   cft.setAttribute("align", "right");
}

 

JavaScript

Posted by arkgame