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

masterems
Newbie
Level:
0
Reputation:
0
Posts:
10
Likes:
0
Credits:
20
10-04-2018, 03:08 AM
#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

YarNulled
Newbie
Level:
0
Reputation:
0
Posts:
17
Likes:
1
Credits:
9
20-03-2020, 09:03 PM
#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

00tester
Newbie
Level:
0
Reputation:
0
Posts:
16
Likes:
8
Credits:
69
19-04-2020, 07:32 AM
#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

20-10-2020, 07:39 AM
#14
Graciasss.....gracias y nuevamente gracias....A seguir trabajando

RE: HELP! DIFFERENCE BETWEEN DIV CLASS AND DIV ID

johanpieter
Lurker
Level:
0
Reputation:
0
Posts:
4
Likes:
0
Credits:
5
21-10-2020, 08:28 PM
#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

the_chi3f
Newbie
Level:
0
Reputation:
0
Posts:
15
Likes:
0
Credits:
15
26-10-2020, 04:50 PM
#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

CornCake
Novice
Level:
0
Reputation:
0
Posts:
20
Likes:
0
Credits:
0
26-10-2020, 09:02 PM
#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

eaminev6
Lurker
Level:
0
Reputation:
0
Posts:
4
Likes:
1
Credits:
4
26-10-2020, 09:08 PM
#18
#yourId {
color: red;
}

for classes you use:

.yourClass {
color: red;
}

Users browsing this thread: 1 Guest(s)