Skip to content
keishi edited this page Jul 6, 2012 · 6 revisions

Element ID

ID mapping is managed inside the TreeScope.

getElementById

Mozilla's case

ID lookup is performed through nsDocument::mIdentifierMap.

    /* mIdentifierMap works as follows for IDs:
     * 1) Attribute changes affect the table immediately (removing and adding
     *    entries as needed).
     * 2) Removals from the DOM affect the table immediately
     * 3) Additions to the DOM always update existing entries for names, and add
     *    new ones for IDs.
     */
    nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;

nsIdentifierMapEntry::mIdContentList contains the list of elements with the same id. They are already sorted, so all GetIdElement() needs to do is return nsIdentifierMapEntry::mIdContentList[0].

Clone this wiki locally