tags:

views:

53

answers:

4

What is the cleanest way to group elements that will be scattered throughout a page (i.e. they cannot all be contained within a single fieldset or other container)?

1) Use the class attribute ... (or limit using this for CSS classes?)

<div id="region1">
    <p class="primary">stuff</p>
    <div class="secondary">stuff</div>
</div>
stuff
<div id="region2">
    <div class="secondary">stuff</div>
    <div class="primary">stuff</div>
</div>

2) Use a "group" attribute ... (or avoid non-standard attributes on the elements?)

<div id="region1">
    <p group="primary">stuff</p>
    <div group="secondary">stuff</div>
</div>
stuff
<div id="region2">
    <div group="secondary">stuff</div>
    <div group="primary">stuff</div>
</div>

3) Some other way ???

+2  A: 

Class attributes, this allows you to use the class selector, in CSS.

LnDCobra
A: 

Personally I prefer class statement, which is standard.

Enrico Carlesso
A: 

As far as you are not using css class name as data containers, they are fine. If you need to store meta data within your elements do it with javascript.

Boris Guéry
I don't understand. Can you elaborate on this?
Robert Claypool
Depending on what you want to establish a relationship, you should use either proper html, for semanticly related element, css for decorations, and javascript to store data which will be used to enhance user experience.
Boris Guéry
+1  A: 

Class. Three reasons:

1) There's no observable semantic difference between 'group' and 'class'.

2) All browsers that can handle CSS can handle class selectors--not all can handle [group=whatever].

3) Typing [group=whatever] takes both more thought and more typing than .whatever.

D_N