Home > Web Front-end > HTML Tutorial > Xin Xing briefly analyzes the difference between name and id in html_html/css_WEB-ITnose

Xin Xing briefly analyzes the difference between name and id in html_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:43:00
Original
1000 people have browsed it

Maybe novice friends can easily distinguish id and class, but they may not be able to easily distinguish id and name. Let’s talk about the difference and connection between the two.

First is the connection. They can both be used to mark an element and can be operated with JavaScript, but the operation methods are different. GetElementById and getElementByName are used to locate DOM nodes respectively.

Then there is the difference. This is very simple. The first is an outline: name is used for the form, and id is used for the style.

When we submit data in a post, in order to distinguish each element in the form, we use name to distinguish. We cannot obtain the content of each form element through the id.

When we are doing CSS styles, we can create an id style sheet. At this time, with # as the prefix, the style with the id will take effect directly, but the name style sheet cannot be created.

In short, it’s still the same sentence: name is mainly used for forms, and id is mainly used for styles.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template