Element.hasAttributes()
Метод Element.hasAttributes()
возвращает Boolean значение, указывая содержит данный элемент какие-либо атрибуты или нет.
Синтаксис
var result = element.hasAttributes();
result
-
содержит возвращаемое значение
true
илиfalse
.
Пример
js
var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
// do something with 'foo.attributes'
}
Polyfill
js
(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