Robert Mark Bram said:
When do I call something a property and when do I call something an
attribute?
The traditional usage is (if I understand it correctly):
- Javascript objects have properties. In "obj.foo" or "obj['foo']",
"foo" is the name of the property. Some properties are functions and
are sometimes called "methods". That is the terminology used in, e.g.,
the ECMS262 specification.
- HTML tags have attributes. In "<body onload='init()'>", "onload='init()'"
is an attribute. We call "onload" the attribute name and "'init()'" is the
attribute value. That is the terminology used in the HTML specifications.
- CSS rules have properties. In "#foo {width:50px;color:red;}" the
(CSS) properties are "width" and "color". That is the terminology used
in the CSS specifications.
Where it becomes fun is when you write things like:
<div id="foo" style="color:red;">
and later
document.getElementById("foo").style.color="green";
- "document" is a global variable (a property of the global object),
and it refers to the document object.
- "getElementById" is a property of the document object. It is a function
so we call it a method.
- The name "foo" refers to the id attribute of the div tag, and the DOM
*element* (an object) returned by the function call is the DOM
representation of the div *tag*.
- The "style" property of the div element corresponds to the "style"
attribute of the div tag.
- the "color" property of the style element corresponds to the CSS property
"color".
/L