0

I can't figure out what the role of the three highlighted Id's is.

Does it change anything related to the final result / optimization wise / structural wise ? Is it something purely structural ?

I understand that the class is linked to .discounted bargain and .damaged stock and the last paragraph id is linked to the #special section but what about the three ID's above . What is the purpose of those ?

I ran it in a browser after deleting the first 3 ID's but the output is still the same as in the one with the ID's.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • We have no way of knowing why the author of that HTML gave IDs to elements without any obvious use of them. We can only guess. – Quentin Nov 26 '20 at 15:57

3 Answers3

1

From: https://css-tricks.com/the-difference-between-id-and-class/

ID’s are unique

  • Each element can have only one ID
  • Each page can have only one element with that ID

Classes are not unique

  • You can use the same class on multiple elements.
  • You can use multiple classes on the same element.

Elements can have BOTH. CSS doesn’t care. JavaScript cares. If you don’t need them, don’t use them.

I hope that helps?

Jon

Jad
  • 1,257
  • 12
  • 19
1

Well an id is like an identifier for a particular element in the DOM, its unique for each element. Imagine like you want to identify an element and how do you do that, its done with the id.mIn the above code snippet the id's are defined but they are not used in the css for doing anything like applying a particular style so thats the reason when u remove them the output is still the same. If you lets say set a color to a div using its id in the css and then remove the id, the style wont apply.

Anurag S
  • 145
  • 1
  • 7
0

Ids are used for targeting specific Elements in html code for further edithing using css or javascript and so on... but the Ids which you used here, you did not use them in your css file, and some how they are not useful for you right now, so you can delete them and it would not change anything.

HamiD
  • 1,075
  • 1
  • 6
  • 22
  • Thank you very much for your answer . This was part of a worksheet and I tried to work it by myself and i just could not understand why those were used . Everything makes sense now . – Augustin12 Nov 26 '20 at 15:56
  • Also , if I would like to add another type of styling to one of the ID's that I didn't use I should add a class after it right ? In other words after applying a certain style to the ID you need to add a class for further styling ? – Augustin12 Nov 26 '20 at 16:10
  • if you want to apply a style on on element on the page, you sould use IDs, but if you want to applay the same style on multiple elements, you need to add class to the elements. it dosnt't matter if your elements have allready class or you add new classes. its just about targetting them. – HamiD Nov 30 '20 at 12:59