Check if the button element has an onclick attribute:
The result will be:
The hasAttribute() method returns true if the specified attribute exists, otherwise it returns false.
![]()
The hasAttribute() method is supported in all major browsers.
Internet Explorer 8 and earlier does not support this method.
| Parameter | Type | Description |
|---|---|---|
| attributename | String | Required. The name of the attribute you want to check if exists |
| Type | Description |
|---|---|
| Boolean | true if the element has attributes, otherwise false |
| DOM Version | Core Level 2 |
|---|
Your message has been sent to W3Schools.