Introduction to the differences between HTML name, id, class (format/application scenario/features), etc.

Introduction to the differences between HTML name, id, class (format/application scenario/features), etc.
In a page, there are many controls (elements or tags). In order to operate these tags more conveniently, they need to be marked with an identity card.

The attributes required are: name, id, class

1. name

Specify a name for the tag.

1.1 Format: <input type="text" name="username" />

1.2 Application Scenarios

①form: name can be used as the variable name of the form list transferred to the server; for example, the name transferred to the server above is: username='value of text';

②Input type='radio' radio tag: When the name of several radio tags is set to the same value, a radio selection operation will be performed.

Copy code
The code is as follows:

<input type="radio" name='sex'/>Male
<input type="radio" name='sex'/>Female③Quickly obtain a group of tags with the same name: obtain tags with the same name and perform operations together, such as: changing attributes, registering events, etc.;
[code]
function changtxtcolor() {
var txts = document.getElementsByName('txtcolor'); //Get all tags with name=txtcolor
for (var i = 0; i < txts.length; i++) { //Loop through the tags and change the background color to red
txts[i].style.backgroundColor = 'red';
}
}

1.3 Features

The value of the name attribute is not unique in the current page.

2. id

Specifies the unique identifier of a tag.

2.1 Format: <input type=password id="userpwd" />

2.2 Application scenarios:

①Quickly obtain the tag object based on the unique ID number provided. For example: document.getElementById(id)

② Used as the value of the for attribute of the label tag: Example: <label for='userid'>Username: </label>, which means that when this label tag is clicked, the label with id userid gets the focus.

2.3 Features

The value of the id attribute must be unique on the current page.

3. class

Specifies the class name of the tag.

3.1 Format: <input type=button class="btnsubmit" />

3.2 Application scenarios:

①CSS operation, put some specific styles into a class class, and add this class if you need tags of this style.

3.3 Features:

You can put multiple classes in one class attribute, but they must be separated by spaces; for example: class='btnsubmit btnopen'

<<:  MySQL data aggregation and grouping

>>:  Detailed steps to expand LVM disk in Linux

Recommend

Summary of several principles that should be followed in HTML page output

1. DOCTYPE is indispensable. The browser determin...

User experience analysis of facebook dating website design

<br />Related article: Analysis of Facebook&...

Use and analysis of Mysql Explain command

The mysql explain command is used to show how MyS...

Detailed explanation of creating, calling and managing MySQL stored procedures

Table of contents Introduction to stored procedur...

CSS3 realizes various graphic effects of small arrows

It’s great to use CSS to realize various graphics...

Detailed tutorial on installing MySQL offline on CentOS7

1. Delete the original mariadb, otherwise mysql c...

Detailed explanation of count without filter conditions in MySQL

count(*) accomplish 1. MyISAM: Stores the total n...

How to implement input checkbox to expand the click range

XML/HTML CodeCopy content to clipboard < div s...

HTML hyperlink style (four different states) setting example

Copy code The code is as follows: <style type=...

...

JavaScript example code to determine whether a file exists

1. Business Scenario I have been doing developmen...

JavaScript to implement slider verification code

This article shares the specific code of JavaScri...