...

View Full Version : Very Simple Question! . vs #



Crash1hd
01-05-2004, 04:21 AM
Ok This is a really simple question! I was wondering what is the difference between useing

#Name

or

.Name

In the scripts?

:confused: :confused: :confused: :confused: :confused:

Its been bugging me and I cant find any reference to it that I can see!

Thanks:D

Skyzyx
01-05-2004, 04:25 AM
In the scripts? I'm not sure about that, but in CSS you'd use "#" to signify an id, while you'd use a "." to signify a classname.

Crash1hd
01-05-2004, 04:31 AM
oh so you use div id with # and div class with .

Mhtml
01-05-2004, 05:53 AM
Yeah ...




...
div#myDiv {
color: orange;
border: solid 2px black;
}

div.myDiv {
color: blue;
border: dashed 1px green;
}
...

<div id="myDiv">myDiv with id attribute</div>
<div class="myDiv">myDiv with class attribute</div>


That would return 2 completely different styled divs. A note also that the same id can only be used on 1 element per page whereas class can be used on as many as you want.

me'
01-05-2004, 11:40 AM
And that ids are easier to work with once you get into the DOM, so use them when you can.

brothercake
01-05-2004, 10:06 PM
Originally posted by me'
And that ids are easier to work with once you get into the DOM, so use them when you can.
Not really .. don't use an ID instead of a class just because you *might* want to identify that element in the DOM. If you *do* then add an ID, but otherwise classes are generally better for CSS because you'll have less code repetition, or smaller rules.

Mind you, ID selectors have higher specificity than class selectors, which can be useful.

Mhtml
01-06-2004, 03:38 AM
Unless of course you are working with invalid xhtml :p ..

me'
01-06-2004, 04:38 PM
Originally posted by brothercake
but otherwise classes are generally better for CSS because you'll have less code repetition, or smaller rules. Oh yeah, of course, if you have a list of things that need to similary styled, use a class, but if you're referring to an individual element, there's normally absolutely nothing to say whether you should use classes or ids, so I'd use an id just because I might want to access it with the DOM.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum