CodesCompiler
πŸ”
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact πŸš€ Get Started Free

JavaScript - DOM Attributes (Attr)

HTML - DOM Attribute (Attr)

The attribute interface in the Document Object Model (DOM) represents attributes of an element as an object. And, this object represents an HTML attribute, through which we can control the functionality of HTML elements.

The attributes of an element are stored in an array-like unordered collection called NamedNodeMap. You can access nodes of this array using its name or index. The indexing starts from 0.

For example, thesrcattribute of an<img>element defines the path to the image to be displayed. Let’s see how to get the name of id attribute βˆ’

HTML DOM Attribute name Property

HTML DOM Attribute name PropertyClick on the below image to get it’s attribute

Example

The code for above example is given below βˆ’

Preview

HTML DOM Attribute Properties

The following table contains a list of DOM Attribute properties βˆ’

Sr.NoProperties & Description1.valueThis property is used to set or get the value of an attribute.2.specifiedIt checks whether the mentioned attribute is specified or not.3.nameIt is used get the name of the used attribute on an element.4.isIdThis property determines whether a HTML attribute is an β€˜id’ attribute or not.