Javascript - DOM Attributes
var element = document.getElementById('...');
element.alt = 'Some text';
var altText = element.alt;
var value = element.value;
getAttribute
setAttribute
| Normalized name | Source name |
|---|---|
| class | className |
| cssFloat | styleFloat for IE, cssFloat for other browsers (when used with .css) |
| float | styleFloat for IE, cssFloat for other browsers (when used with .css) |
| for | htmlFor |
| maxlength | maxLength |
| readonly | readOnly |
| styleFloat | styleFloat for IE, cssFloat for other browsers (when used with .css) |
What are different ways to get the value of a particular attribute of an element?
var altText = element.alt; // Access the attribute directly
getAttribute
What are different to assign a value to particular attribute of an element?
element.alt = altText; // Assign the value to the attribute directly
setAttribute
page revision: 3, last edited: 24 Sep 2016 08:57





