JavaScript UniqueID Properties

Source: Internet
Author: User

Every HTML element in a Web page has an id attribute, and the ID is the identifier, and it should be unique in our general understanding. But the id attribute of the HTML element is writable, which makes it very possible for us to artificially repeat the ID. What if the ID is repeated? How do we get a unique label for the HTML element?

Because IE has very good fault tolerance for HTML code that is cluttered with formatting (incomplete or faulty nesting relationships), it is a piece of cake for the HTML element ID repetition problem. Suppose such a situation arises, for example:<DivID= "Divtext">The first line .</Div>
<DivID= "Divtext">The second line.</Div>


The Divtext is not a reference to the DIV element, but an array of two elements, sorted by the sequence of two DIV elements appearing in the DHTML Object Tree.

How does this ID work? Do you think there is a feeling of being swayed by IE?!

Fortunately, ie precipice, after 5.0, provides an UniqueID read-only property for HTML elements.  This is good, to make it into a readonly, see ya still disorderly?! Fortunately really not disorderly, just how to say this UniqueID interesting? Since UniqueID itself does not provide the default value, IE will not assign UniqueID to HTML elements after parsing the HTML code to build the DHMTL tree. This UniqueID value is generated only after we have visited the UniqueID property of the HTML element. In fact, it's lazy initialize technology, just put here and think it's more fun. For Uniquenumber, it is relative to UniqueID, and the UniqueID format is: ms__id/d+. That is, a "ms__id" prefix plus a serial number. So this uniquenumber is a separate indication of that running number.

UniqueID The second interesting place is that the Document object also has this property, except that it is completely different from other HTML's UniqueID properties. When we call Document.uniqueid every time, the system will return a new UniqueID value, just doucment no uniquenumber attribute ha.

And then I remembered that when I was using the popup form to make an infinite menu, I constructed the __menucache__ class, and realized a unique ID of the generated structure, some superfluous.

#1楼 [Landlord] Reply reference view

By the way, it is because the HTML element's UniqueID is generated by the lazy load method. So no matter what the detailed value of the UniqueID of an HTML element has nothing to do with its position in the DHMTL tree, the UniqueID of an HTML element is simply guaranteed to be in a single page scope unique!

2005-02-19 02:19 | Birdshome

JavaScript UniqueID Properties

Related Article

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.