Frontend Development

HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

Submitted by Avocat, , Thread ID: 61633

Thread Closed

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#11
07-12-2017, 04:18 AM
prankycrank Wrote:
The difference is quite obvious usually ID is always unique so can use it only one element, but the class refers to a group with similar properties so you can use it with multiple elements.

Its is a best response. ID always unique and is to use on one element.

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#12
using class for styling CSS and using ID for JS is good way of coding

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#13
You need to remember, that you can have multiple classes per element and sigle class can be re-used as much as you can, but IDs are unique per page.

Both, classes and IDs have multiple usses.
First of all you can use both for styling purposes.
in css for id you simply style it as:
#yourId {
color: red;
}

for classes you use:

.yourClass {
color: red;
}

both of them will change color of the text in the elements with corresponding classes and ids to red.

IDs also hase a single extremey useful native function. They are used for navigation.

If you have an element on your site with an id for example id="yourPageElement" you can add #yourPageElement in the end of the URL of the page and it will automatically scroll the element into view.
This is usefull for example for a button that will scroll you to the top of the page.
This can be achieved by a link like this: a href="#yourPageElement"

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#14
Graciasss.....gracias y nuevamente gracias....A seguir trabajando

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#15
Class can you use for multible elements stlyling. ID is for one and only specific element

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#16
think it as a real life example, ID is to identify 1 and only 1 think you want to edit, class can be used multiple times

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#17
id is a unique, so It can only use once while class can be use many times as you want. It's better to use class rather than id.

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

#18
#yourId {
color: red;
}

for classes you use:

.yourClass {
color: red;
}

Users browsing this thread: 4 Guest(s)