What is the difference between id and name in html

青灯夜游
Release: 2021-11-01 16:07:56
Original
10795 people have browsed it

Difference: 1. The value of the id attribute is case-sensitive, and each id value should be unique; while the name attribute is not unique, and its value can be reused. 2. The uses are different. The id attribute can be used as an anchor reference or an ID selector; while the name attribute is used in forms to submit information.

What is the difference between id and name in html

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

In HTML, both the id attribute and the name attribute provide identifiers to represent HTML element tags. So what's the difference between them? This article will give you a brief comparison of the id attribute and the name attribute, and introduce the difference between the id attribute and the name attribute. I hope it will be helpful to you.

id attribute in html

We use the id attribute to identify a unique HTML element, which can be used as an anchor reference in the URL (URL with # symbol), or in css Use an ID selector to style the element. You can also use getElementById() in javascript to find elements through the id attribute value and then operate on the elements. Example:

测试文本!测试文本!

测试文本!测试文本!

Copy after login
What is the difference between id and name in html
##
Copy after login
What is the difference between id and name in html
The id attribute is universally compatible and valid for any element. And the value of the id attribute is case-sensitive, and each id value should be unique. Example:

div标签,id值为a

p标签,id值为A

Copy after login
#a{ color: red;}
#A{ color: pink;}
Copy after login

Rendering:

What is the difference between id and name in html
The name attribute in html

The name attribute is also used to identify HTML elements, but it does not have a unique row. Its value can be reused, for example: radio button

最喜欢水果?






Copy after login

Rendering:

What is the difference between id and name in html##As shown in the above example, name The attribute is often used in forms to submit information; it is only valid for tag elements such as a, form, iframe, img, map, input, select, textarea, etc.

The name attribute can be used in JavaScript to find elements using getElementsByName(); but it cannot be referenced in CSS or URLs. Example:



 
 




Copy after login
Rendering:

What is the difference between id and name in html

Description:


It can be said that ID is a person's ID number, and Name is the person's name. Both can exist at the same time, sharing the same namespace (the values ​​of both can be the same).

Recommended tutorial: "

html video tutorial

"

The above is the detailed content of What is the difference between id and name in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 [email protected]
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!