Does "myButton" have an onclick attribute:
let answer = myButton.hasAttribute("onclick");
Try it Yourself »
If an <a> element has a target attribute, change the value to "_self":
if (element.hasAttribute("target")) {
element.setAttribute("target", "_self");
}
Try it Yourself »
The hasAttribute()
method returns true
if the attribute exists, otherwise false
.
element.hasAttribute(
name)
Parameter | Description |
name | Required. The name of the attribute. |
Type | Description |
Boolean | true if the element has the attribute, otherwise false . |
element.hasAttribute()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!