Javascript - DOM Attributes

javascript
javascript-dom

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
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License