Hi
Whats the difference between id & class in a div tag?
Which one should be used and in what situation?
Thanks for the info on this.
Shyn3
Hi
Whats the difference between id & class in a div tag?
Which one should be used and in what situation?
Thanks for the info on this.
Shyn3
id's are used when it will only be applied to ONE div.
classes are used when it's required more than once.
Example:
HTML Code:<div id="onlyone"></div> <div class="multipleones"></div> <div class="multipleones"></div> <div class="multipleones"></div>
Thou com'st in such a questionable shape
Hamlet, Act 1, Scene 4
Yes, and remember to think ahead: just because there might only be one now, there may be more in the future. Use the id attribute when something is truely unique.
There is an exception: if the element needs to be accessed from a script, assigning it an id attribute value makes obtaining a reference to the element much easier.
Mike
Quite, and I hope I didn't imply otherwise. An id attribute value must be completely unique within a document; it cannot be duplicated.
No, there isn't. However, one can write such a function with the aid of the getElementsByTagName method.If I recall, there's a thing in javascript that calls things by their class, too. getElementsByClass('classhere') or something?
Mike
Thanks alot makes alot sense to me now.
Doesn't class also affect CSS?
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
One more question. In my page I have everything with class, there is no id attribute. i have two columns, left column is a menu and right menu is the content and sometimes when I access the page it messes up the content column and shifts it position to the bottom of left column. Someone suggested I rename the class name and I tried that too but it didn't work. What could be causing this??
Bookmarks