[whatwg] Attributes vs. Elements
news at terrainformatica.com
Mon Mar 12 13:19:38 PDT 2007
----- Original Message -----
From: "Maciej Stachowiak" <mjs at apple.com>
To: "WHATWG Mailing List" <whatwg at whatwg.org>
Sent: Monday, March 12, 2007 10:25 AM
Subject: [whatwg] Attributes vs. Elements
| The recent discussion of possibly making the href attribute global
| brings to mind a broader issue. To what extent should semantics and
| behavior belong to specific elements, and to what extent should they
| be carried by global attributes that can apply to any element?
| XHTML2 moves a lot of semantics and behavior from elements to global
| attributes. For example, href can turn any element into a hyperlink,
| and src can turn any element into an image.
| HTML5 has so far not taken this approach - elements generally remain
| distinct, and new behaviors and semantics appear in the form of new
| In my opinion, it is usually better to put primary semantics on
| elements rather than attributes. Here are a few reasons, in
| approximate decreasing order of importance:
| - An element is generally seen as a separate thing in itself, whereas
| an attribute is just an attribute. So it is natural to think of an
| element having more semantic strength than an attribute.
No objections in theory. But in practice...
As an example:
Take a look on first column in first table here:
Semantic (meaning) of elements there is
"cell in the table" *and* "link".
<td><a>...</a></td> is perfectly valid from
abstract semantic automata analysing the Web but
it is wrong from human point of view - usability
and accessibility value of this solution is very low.
( he/she consumes semantic in visual on-screen form)
this particular case should be rendered by:
as all topics on the forum have equal semantic value.
<td ><a href="1.htm">xyz</a></td>
<td ><a href="2.htm">xyz-xyz-xyz</a></td>
is perfectly valid from some abstract semantic machine
point of view but for human these two cells are not
equal. At least hit area is different. And visual perception too.
So the question is: whose semantic meaning you are talking
| - Semantics that has associated behavior often has an associated DOM
| API. For example, the A element has a number of attributes related to
| its use as a hyperlink source, to programmatically retrieve or change
| only part of the href URI. If any element could have the href
| attribute, the options become omitting the API, adding it to all
| elements, or (yuck) making it conditionally present on all elements
| based on presence or absence of the attribute.
I do not understand paragraph above.
Even now you can use get/setAttribute methods to get/set 'href'
attribute to any element. So where do you see the problem?
| - It's easier (and, in many implementations, more efficient) to style
| by tag name rather than by presence or absence of an attribute.
Why do you think that selector "a:link" is easier than ":link" ?
| - Typically, browser implementations have an implementation class per
| element, but not a class per attribute, so putting primary semantics
| and behavior on an element instead of an attribute promotes clean
| implementation. Otherwise, all behavior ends up in the HTMLElement
| base class.
I do not really understand this too:
"browser implementations have an implementation class per element"
Anyway attribute selectors are citizens of the same class as any
others in CSS. What problem do you see with them?
| Finally, I'd like to conclude with this reductio ad absurdum of the
| XHTML2 approach. If assigning behavior and semantics to attributes is
| so much better, why not just have a single <elt> element:
| <elt role="paragraph">My cat is really cute: <elt
| src="mycat.jpeg">picture of my cat</elt>. Check out <elt
| href="story.html">this <elt role="emphasis">hilarious</elt> story
| about her</elt>.</elt>
True, any idea at some stage can become an absurd one.
This is also valid for the statement:
"Each DOM element has one and only one semantic meaning for
human". Reality is more colorful than that.
| I find the HTML approach much more readable and more semantically clear:
| <p>My cat is really cute: <img src="mycat.jpg" alt="picture of my
| cat">. Check out <a href="story.html">this <em>hilarious</em> story
| about her</a>.</p>
This particular example makes sense for me too. As I guess example
with my forum above for you.
More information about the whatwg