SetAttribute
setAttribute is a method on DOM elements that sets or updates the value of a named attribute on an element. It takes two string arguments: the attribute name and the new value. If the attribute did not previously exist, it is created; if it did exist, its value is updated. In HTML documents, the value becomes the string representation of the provided value. For boolean attributes (such as disabled, checked, or selected), the presence of the attribute is what matters: setting a value with setAttribute generally enables the attribute, while removing the attribute disables it.
For XML or when namespaces are involved, there is a separate method called setAttributeNS that allows specifying
setAttribute is distinct from property assignment. Many attributes map to DOM properties; for example, an element’s