SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
May 22, 2002, 15:40 #1
- Join Date
- Aug 2001
- Location
- Los Angeles, CA
- Posts
- 346
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ID's and Classes... The difference is....?
Hello,
I just wanted to ask if there's any difference with ID's and Classes beside's a Class's functionality to work hierarchically with JavaScript.
Are there any advantages IDs have over Classes that I don't know about? What's the official difference, if the Class's JS functionality isn't it?
Thanks,
GregC
-
May 22, 2002, 15:43 #2
- Join Date
- Aug 1999
- Location
- Lancaster, Ca. USA
- Posts
- 12,305
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Simply put it is like this...
ID's are for single elements. If you use the element or formatting once per page then an ID is useful... i.e.
#header {formatting stuff here}
#footer {formetting stuff here}
Classes are useful when you need the same formatting on more than one element such as links or images.
i.e.
.headerlinks {formatting stuff here}
.footerlinks {formatting stuff here}
-
May 22, 2002, 16:09 #3
- Join Date
- Jan 2001
- Location
- Lawrence, Kansas
- Posts
- 2,066
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In addition, IDs are very handy for using javascript to manipulate your pages via the DOM. If something has a unique ID you can access it by calling document.getElementByID('idtag') where idtag is the ID attribute of the element you wish to access.
-
May 23, 2002, 10:35 #4Originally posted by W. Luke
Simply put it is like this...
ID's are for single elements. If you use the element or formatting once per page then an ID is useful... i.e.
#header {formatting stuff here}
#footer {formetting stuff here}
Classes are useful when you need the same formatting on more than one element such as links or images.
i.e.
.headerlinks {formatting stuff here}
.footerlinks {formatting stuff here}
-
May 23, 2002, 14:41 #5
Bookmarks