...

View Full Version : Use of an id keyword



zedan85
08-14-2011, 02:43 AM
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

DaveyErwin
08-14-2011, 02:51 AM
no javascript necessary


<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>

zedan85
08-14-2011, 02:58 AM
no javascript necessary


<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..

teedoff
08-14-2011, 03:10 AM
Perhaps this will help:
http://www.tizag.com/cssT/cssid.php

DaveyErwin
08-14-2011, 03:15 AM
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.

zedan85
08-14-2011, 03:16 AM
Perhaps this will help:
http://www.tizag.com/cssT/cssid.php

Thanks for the reference.. that cleared a lot..:cool:

vikram1vicky
08-14-2011, 12:43 PM
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...

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum