Hassan Schroeder wrote:
> On Wed, Feb 18, 2009 at 8:38 AM, bill walton <[email protected]>
> wrote:
>
>> We've got three 'identifiers' to work with: id, name, and class. CSS
>> uses id and class. Javascript uses id and name. So, to keep the issues
>> as separate as possible, I try to avoid using id for CSS.
>
> Huh?? JavaScript offers various ways to access elements of the
> DOM, and 'class' is certainly one of them. Can you be more specific
> about what "issues" you're trying to "keep separate"?
>
> And if you have *one* of an element that needs styling, why not use
> an ID to target your CSS?
>
> --
> Hassan Schroeder ------------------------ [email protected]
To add a couple of point to this: First the name attribute is deprecated
because it turned out to be a mistake. It server the exact same purpose
as id and it redundant. Secondly, any sane person uses something like
jQuery or Prototype, which access elements in the DOM using CSS
selectors. So the trend is to try to bring JavaScript and CSS closer
together and not to separate them.
So given that there is not three identifiers there is just one, which is
id. The class attribute does not identify a DOM element. It identifies
the styles to apply to the element. Notice I said styles (plural).
This is perfectly legal:
HTML fragment
----
<ul id="articles">
<li id="article_1" class="article_title">
...
</li>
<li id="article_2" class="article_title selected">
...
</li>
<li id="article_3" class="article_title">
...
</li>
</ul>
CSS
-----
.article_title {
font-size: 14pt;
font-color: blue;
font-weight: bold;
}
.selected {
background-color: #ffc;
}
Notice that all id attributes are unique on the page and are used to
identify DOM elements. CSS class names describe the styling and are not
used to identify the DOM elements.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---