Wednesday, September 21, 2011

13 - Difference Between ID and Class


 ID Selectors: 


According w3c rules it is wise to use id on one and unique Selector. If we used a id called "myText" on selector p, it is not good to use same id "myText" on other p or other Selectors.



 Class Selectors:


Unlike id we can use same class to style more than Selectors.
This allows you to set a particular style for many HTML elements with the same class.  


Que: 

Yes, i know that two elements can't hav the same id but i want to know is there any potential risk in this usage of id?

 Ans:


ID is short for identification ... so it must be unique. It may well work just fine with CSS, but you'll almost certainly have problems if you try and get those elements in Javascript.



 powered by multimediagyan ©

No comments:

Post a Comment