Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Use of an id keyword

    Hi being fairly new to CSS/HTML/Javascript.
    I had a question is mind while reading tutorials on CSS i saw that most examples made use of the class keyword (attaching/affiliating tags to classes)
    such as
    <t class="ex">This is a paragraph with class="ex". This text is blue.</t>

    but rarely did i ever come across the id keyword until now in javascript.
    Could you guys tell me how often is the id keyword used ?? or do u just use it when you want to affiliate some java script with a tag???thanks

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    no javascript necessary

    Code:
    <html>
    
    <head>
    
    <title>id keyword</title>
    <style>
    #myDiv{color:red;}
    </style>
    </head>
    
    <body>
    <div id="myDiv">I'm red</div>
    <div>I'm not red</div>
    </body>
    
    </html>

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DaveyErwin View Post
    no javascript necessary

    Code:
    <html>
    
    <head>
    
    <title>id keyword</title>
    <style>
    #myDiv{color:red;}
    </style>
    </head>
    
    <body>
    <div id="myDiv">I'm red</div>
    <div>I'm not red</div>
    </body>
    
    </html>
    Thanks for the example.. though i am a bit confused now.could you tell me abt the # symbol you used... a link to this reference would be great..

  • #4
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Perhaps this will help:
    http://www.tizag.com/cssT/cssid.php
    Teed

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Quote Originally Posted by zedan85 View Post
    Thanks for the example.. though i am a bit confused now.could you tell me abt the # symbol you used... a link to this reference would be great..
    yes, the octothorpe stipulates an id.

  • #6
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by teedoff View Post
    Perhaps this will help:
    http://www.tizag.com/cssT/cssid.php
    Thanks for the reference.. that cleared a lot..

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    in short....

    ID is used to target a particular unique element in whole page and ID is used in styling (CSS), client side scripting/effect (jquery/Javascript and server side scripting (ASP, PHP....

    CSS defined for an ID, may be used for 1 element only having that ID

    Where class is mainly used for styling a web page (CSS), however it can be used in scripting also... A class defined in CSS can be used N number of times with all elements...



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •