VOOZH about

URL: https://www.geeksforgeeks.org/html/html-dom-createattribute-method/

⇱ HTML DOM createAttribute() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML DOM createAttribute() Method

Last Updated : 11 Jul, 2025

This createAttribute() method is used to create an attribute with the specified name and returns the attribute object. The attribute.value property is used to set the value of the attribute and the element.setAttribute() method is used to create a new attribute for an element. This method() contains the name of the created attribute as a parameter value. 

Syntax:

document.createAttribute( attributename )

Example: In this example, we will use the createAttribute() method.

Output:

👁 Image

Example 2: In this example, we will use the createAttribute() method.

Output:

👁 Image

Supported Browsers: The browser supported by DOM createAttribute() method are listed below:

Comment
Article Tags: