Very interesting uniqueid & uniquenumber attributes

Source: Internet
Author: User
Each HTML element on the web page has an ID attribute, and ID is used as its identifier. In our general understanding, it should be unique. However, the ID attribute of HTML elements is writable, which may lead to human duplication of IDs. What if the ID already exists? How can we get a unique identifier for the HTML element?

Due to IE's chaotic format (incomplete or wrong nesting relationships ),CodeDue to excellent fault tolerance, the ID duplication problem of HTML elements is simply a piece of cake for it. If this happens, for example:

< Div ID = "Divtext" > The first line. </ Div >
  < Div ID = "Divtext" > The second line. </ Div >

In this case, divtext is not a reference to the DIV element, but an array containing two elements, which are sorted by the order in which the two DIV elements appear in the DHTML Object Tree.

How can I use such an ID? Do you think there is a feeling of being shaken by IE ?!

Fortunately, ie gets lost and provides a uniqueid read-only attribute for the HTML element after 5.0. Now, let's make it readonly. Is it still messy ?! Fortunately, this is really not messy, but how can this uniqueid be interesting? Because uniqueid itself does not provide the default value, that is, ie will not assign the uniqueid to the HTML element after parsing the HTML code and building the dhmtl tree. You need to access the uniqueid attribute of the HTML element to generate the uniqueid value for it. It is actually the lazy initialize technology, but it is more fun to put it here. For uniquenumber, it is relative to uniqueid. The format of uniqueid is MS _ ID \ D +. That is, a prefix of "MS _ id" and a serial number are added. Therefore, this uniquenumber represents the sequential number.

The second interesting part of uniqueid is that the document object also has this attribute, But it and other HTML uniqueid attributes make sense completelyDifferent. Every time we call document. uniqueid, the system returnsNewUniqueid value, but doucment does not have the uniquenumber attribute.

At this time, I remembered that when I used the popup window to create an unlimited menu, the _ menucache _ class was constructed to implement a unique ID generation structure. This would be a little more.

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.