--- title: Element.hasAttributes() slug: Web/API/Element/hasAttributes translation_of: Web/API/Element/hasAttributes ---
{{ApiRef("DOM")}}

Метод Element.hasAttributes() возвращает Boolean значение, указывая содержит данный элемент какие-либо атрибуты или нет.

Синтаксис

var result = element.hasAttributes();
result
содержит возвращаемое значение true или false.

Пример

var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
    // do something with 'foo.attributes'
}

Polyfill

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

Спецификация

Specification Status Comment
{{SpecName("DOM WHATWG", "#dom-element-hasattributes", "Element.hasAttributes()")}} {{Spec2('DOM WHATWG')}} Moved from the {{domxref("Node")}} interface to the more specialized {{domxref("Element")}} interface.
{{SpecName('DOM3 Core','#ID-NodeHasAttrs','hasAttributes()')}} {{Spec2('DOM3 Core')}} No change from {{SpecName("DOM2 Core")}}
{{SpecName('DOM2 Core','#ID-NodeHasAttrs','hasAttributes()')}} {{Spec2('DOM2 Core')}} Initial definition, on the {{domxref("Node")}} interface.

Совместимость с браузерами

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} [1] 9 {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

[1] Before Firefox 35, it was implemented on the {{domxref("Node")}} interface.

Смотрите также