The difference between name and id in html.
Maybe New friends can easily distinguish between id and class, but it is not necessarily easy to distinguish between id and name. Let's talk about the difference and connection between the two.
First, contact. They can be used to mark an element and can be operated using JavaScript. However, different operation methods use getElementById and getElementByName to locate DOM nodes respectively.
Then there is the difference. This is very simple. First, it is an outline: name is used for forms, and id is used for styles.
When submitting data through post, we use name to differentiate the elements in the form. We cannot obtain the content of each form Element Through id.
When creating a css style, you can create an id style table. At this time, the style with the id prefix # takes effect directly, but the name style table cannot be created.
In a word, name is mainly used for forms, and id is mainly used for styles.