hasAttributes() method is used to check and return whether an element has any type of attributes or not.
This method returns Boolean value.
Example - Check if an element has any attributes
- In the next step we are using the if.. else statement.
- In the if statement we are checking if the elem variable has any attributes in it.
- Since two attributes are present, it returns true and the alert statement inside if statement is executed (alert("Given attribute is present");).