Метод 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 |
---|---|---|
DOM Определение 'Element.hasAttributes()' в этой спецификации. |
Живой стандарт | Moved from the Node interface to the more specialized Element interface. |
Document Object Model (DOM) Level 3 Core Specification Определение 'hasAttributes()' в этой спецификации. |
Устаревшая | No change from Document Object Model (DOM) Level 2 Core Specification |
Document Object Model (DOM) Level 2 Core Specification Определение 'hasAttributes()' в этой спецификации. |
Устаревшая | Initial definition, on the Node interface. |
Совместимость с браузерами
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Да) | (Да) [1] | 9 | (Да) | (Да) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | ? | ? | ? | ? | ? |
[1] Before Firefox 35, it was implemented on the Node
interface.