Java Reference
In-Depth Information
swim.getAttribute("class");
<< "swimming"
If an element does not have an attribute, the setAttribute method can be used to add
it to the element. For example, we can add an id of "run" to the run paragraph:
run.setAttribute("id","run");
<< undefined
run.getAttribute("id");
<< "run"
Note: Legacy DOM Attributes
The legacy DOM allows access to attributes using dot notation, like so:
bike.id;
<< "bike"
This notation is still supported, although some attribute names such as
class and for are reserved keywords in JavaScript so we need to use
className and htmlFor instead:
swim.className;
<< "swim"
Search WWH ::




Custom Search