Jump to content

HTML id attribute


dantepicchioni
 Share

Recommended Posts

Dear Colleagues,

Hi.  When you say "You cannot have more than one element with the same id in an HTML document" (https://www.w3schools.com/html/html_id.asp), why do you use the word "cannot"?  Should this not be "should not" because you clearly can.

Sincerely,

Dante
 

Link to comment
Share on other sites

  • 3 weeks later...
  • 6 months later...

If you have multiple IDs in a document, the browser will set the value to the last one.

For example:

<a id="link" href="https://google.com">Google</a>

<a id="link" href="https://yahoo.com">Yahoo</a>

<a id="link" href="https://ebay.com">eBay</a>

In this case, the href value of the id 'link' will be 'https://ebay.com'.

The other two are replaced by the last value.

Can you do it? Sure.

Does it help you? Not one bit.

It doesn't cause your browser to self-destruct or anything. But, you can't write functional Javascript code.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...