Log in

View Full Version : Differences between using "id" & "class"



ajmaske
11-21-2007, 07:44 AM
What is the difference between...

#something
{
}

<div id="something"></div>

.somethingelse
{
}

<div class="somethingelse"></div>

When would one be used over the other and vice/versa?

codeexploiter
11-21-2007, 08:12 AM
#something{

}
The above item is known as ID Selector. The idea is you can use this ID Selector only on a single HTML element as its ID. ID is supposed to be a unique value within a web page. In other words you can use the above mentioned item only once.


.somethingelse
{
}

The above is the class selector. The advantage of this over the ID selector is you can re-use this class on any number elements using the 'class' attribute of that element which needs to use the CSS class.