Must the ID value be unique in HTML?

Source: Internet
Author: User

HTML Experiment:

1. Create a new webpage, enter the content, open it in the browser

<HTML>    <Head>        <Metahttp-equiv= "Content-type"CharSet= "Utf-8"/>    </Head>    <Body>Name:<inputtype= "text"ID= "Intxt"/><BR/>Password:<inputtype= "text"ID= "Intxt"/>    </Body></HTML>

2.

Two input boxes using the same ID number, but can display normally, the browser did not error

CSS Experiment

1. Modify the source code, add style

<HTML>    <Head>        <Metahttp-equiv= "Content-type"CharSet= "Utf-8"/>                <style>#inTxt{Background-color:Red;                }        </style>    </Head>    <Body>Name:<inputtype= "text"ID= "Intxt"/><BR/>Password:<inputtype= "text"ID= "Intxt"/>    </Body></HTML>

2.

JS Experiment

1. Modify the source code, add the script

<HTML>    <Head>        <Metahttp-equiv= "Content-type"CharSet= "Utf-8"/>                <style>#inTxt{Background-color:Red;                }        </style>    </Head>    <Body>Name:<inputtype= "text"ID= "Intxt"value= "a"/><BR/>Password:<inputtype= "text"ID= "Intxt"value= "B"/>                <Script>            varinput=document.getElementById ("Intxt");        alert (Input.value); </Script>    </Body></HTML>

2.

Summarize

1.html has the same ID number, does not affect the display

2.css applies a style to a label with the same ID number in the page

3. Multiple identical ID numbers, JS only go to the first one

Must the ID value be unique in HTML?

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.