Element.hasAttributes()

Метод 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
DOM Standard
# ref-for-dom-element-hasattributes①

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

BCD tables only load in the browser

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