The difference between name and id in html.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.