Element: hasAttributes() method
{{ApiRef("DOM")}}
The hasAttributes() method of the {{domxref("Element")}}
interface returns a boolean value indicating whether the current element has any
attributes or not.
Syntax
hasAttributes()
Parameters
None.
Return value
A boolean.
Examples
let foo = document.getElementById("foo");
if (foo.hasAttributes()) {
// Do something with 'foo.attributes'
}
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("Element.attributes")}}
- {{domxref("Element.hasAttribute()")}}
- {{domxref("Element.getAttribute()")}}
- {{domxref("Element.setAttribute()")}}
- {{domxref("Element.removeAttribute()")}}
- {{domxref("Element.toggleAttribute()")}}
这篇文档对你有帮助吗?
谢谢你的反馈!