This function sets a DOM/HTML property or attribute on an element. The DOM is the browser’s Document Object Model that represents all of the HTML on a page.
- element – the reference to a DOM element
- attribute – the HTML attribute to set
- value – the value to assign to the attribute specified
In this example, we will set the value attribute of a textbox to “Please Enter your name”.
The line of code above is equivalent to:
In the next example, we will disable a textbox so users will not be able to type any information in that textbox. In this case, we assign an onclick event handler function to a button that changes the “disabled” attribute on an input field to true.
Other DOM properties such as size, maxlength, align, etc. can be changed as well depending on the type of DOM element.