Confucion with Class & Id's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    Confucion with Class & Id's

    I am having some confusion with the class & Id. I browsed and got some info regarding the difference between Class & Id in CSS, Class can be used for many tags or elements in the page but Id can be used only once in a page. Instead of doing like that why cant we write the css as inline for that particular tag or element. If we use Id can we use that Id in Javascript, as what we do inorder to get the Element with Id. Please clarify me. I dont know I am correct or wrong.


    Regards
    Ramanan Kalirajan
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Yes, you can use that ID to get the element by its ID using document.getEle mentById().

    The ID can be useful not just for a particular element, but you could do something like this:
    Code:
    #someid p { ... }
    so it would only be applied to p elements contained within the element with ID "someid". That's only a simple example, but you get the idea.

    Comment

    • RamananKalirajan
      Contributor
      • Mar 2008
      • 608

      #3
      Originally posted by acoder
      Yes, you can use that ID to get the element by its ID using document.getEle mentById().

      The ID can be useful not just for a particular element, but you could do something like this:
      Code:
      #someid p { ... }
      so it would only be applied to p elements contained within the element with ID "someid". That's only a simple example, but you get the idea.

      Thanks sir, I can grasp some idea from the example what u had shown in the post

      Regards
      Ramanan Kalirajan

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad you could.

        Comment

        Working...