By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,518 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,518 IT Pros & Developers. It's quick & easy.

Confucion with Class & Id's

RamananKalirajan
100+
P: 607
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
Nov 5 '08 #1

✓ answered by acoder

Yes, you can use that ID to get the element by its ID using document.getElementById().

The ID can be useful not just for a particular element, but you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. #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.

Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Yes, you can use that ID to get the element by its ID using document.getElementById().

The ID can be useful not just for a particular element, but you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. #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.
Nov 5 '08 #2

RamananKalirajan
100+
P: 607
Yes, you can use that ID to get the element by its ID using document.getElementById().

The ID can be useful not just for a particular element, but you could do something like this:
Expand|Select|Wrap|Line Numbers
  1. #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
Nov 5 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad you could.
Nov 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.