0
ID, Name and Class
what is the difference between ID, name and Class?
3 odpowiedzi
+ 6
'name' attribute is specific to form elements (<input>, <select>, and so on) and it's used to indentify date (as a key in a pair key/value) submited to server... however, in Html < 5 it's also an attribute of the <a> tag, but it's deprecated in Html5, and 'id' should be used instead:
https://www.w3schools.com/tags/att_a_name.asp
+ 3
id is used as unique identifier of an element.
class is used for mutiple elements having that property. Name or other attribute is a property of an html tag.
+ 2
Use a class when you want to consistently style multiple elements throughout the page/site. in the Classes more than one element that shares the same style.
Additionally, a given element can have more than one class associated with it, while an element can only have one id. For example, you can give a div two classes whose styles will both take effect.
Use the ID when you have a single element on the page that will take the style. Remember that IDs must be unique.
eg: -main-content, header, footer, or left-sidebar.
* Each element can have only one id
* Each page can have only one element with that id
* You can use the same class on multiple elements.
* You can use multiple classes on the same element.