X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM hasAttribute() Method

Element Object Reference Element Object

Example

Check if the button element has an onclick attribute:

document.getElementsByTagName("BUTTON")[0].hasAttribute("onclick");

The result will be:

true

Try it yourself »

Definition and Usage

The hasAttribute() method returns true if the specified attribute exists, otherwise it returns false.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The hasAttribute() method is supported in all major browsers.

Internet Explorer 8 and earlier does not support this method.


Syntax

element.hasAttribute(attributename)

Parameters

Parameter Type Description
attributename String Required. The name of the attribute you want to check if exists

Return Value

Type Description
Boolean true if the element has attributes, otherwise false

Technical Details

DOM Version Core Level 2 Element Object


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook