Element.hasAttributes()

hasAttributes()Element インターフェイスのメソッドで、現在の要素が属性を持っているか否かを Boolean で返します。

構文

var result = element.hasAttributes();

返値

result

返値を true または false で保持します。

let foo = document.getElementById('foo');
if (foo.hasAttributes()) {
  // Do something with 'foo.attributes'
}

ポリフィル

;(function(prototype) {
  prototype.hasAttributes = prototype.hasAttributes || function() {
    return (this.attributes.length > 0);
  }
})(Element.prototype);

仕様書

Specification
DOM Standard
# ref-for-dom-element-hasattributes①

ブラウザーの互換性

BCD tables only load in the browser

関連情報