index.html 455 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US"><head>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  <title>DOM4</title>
  <!-- W3C only -->
  <style type="text/css">
   pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
   pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
   pre code { color:inherit; background:transparent }
   .example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
   .note { margin-left:2em; font-weight:bold; font-style:italic; color:#008000 }
   p.note::before { content:"Note: " }
   .XXX { padding:.5em; border:solid #f00 }
   p.XXX::before { content:"Issue: " }
   dl.switch { padding-left:2em }
   dl.switch > dt { text-indent:-1.5em }
   dl.switch > dt:before { content:'\21AA'; padding:0 0.5em 0 0; display:inline-block; width:1em; text-align:right; line-height:0.5em }
   dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
   dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
   dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
   dl.domintro dd p { margin: 0.5em 0; }
   dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; }
   em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
   dfn { font-weight:bold; font-style:normal }
   code { color:orangered }
   code :link, code :visited { color:inherit }
   hr:not(.top) { display:block; background:none; border:none; padding:0; margin:2em 0; height:auto }
   table { border-collapse:collapse; border-style:hidden hidden none hidden }
   table thead { border-bottom:solid }
   table tbody th:first-child { border-left:solid }
   table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }

   .warning { color: red; background: transparent; font-weight: bolder; font-style: italic; }
   .warning p:first-child { margin-top: 0; }
   .warning p:last-child { margin-bottom: 0; }
   .warning:before { font-style: normal; }
   p.warning:before { content: '\26A0 Warning! '; }
  </style>
  <style type="text/css">
   @media print {
     [data-anolis-spec]::after { content:"[" attr(data-anolis-spec) "]"; font-size:.6em; vertical-align:super; text-transform:uppercase }
   }
  </style>
  <link class="w3conly" href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css">
  </head>
 <body>

<div class="head">
<div class="w3conly">

<!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
<!--end-logo-->
</div>
 <h1>DOM4</h1>
 <h2 class="no-num no-toc" id="w3c-working-draft-5-january-2012">
  <span class="w3conly">W3C Working Draft 5 January 2012</span>
  </h2>

 <dl>
  <dt>This Version:
  <dd class="publish"><a href="http://www.w3.org/TR/2012/WD-dom-20120105/">http://www.w3.org/TR/2012/WD-dom-20120105/</a>

  <dt class="publish">Latest Version:
  <dd class="publish"><a href="http://www.w3.org/TR/dom/">http://www.w3.org/TR/dom/</a>

  <dt class="publish">Latest Editors' Draft:
  <dd class="publish"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html">http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html</a>

  <dt class="w3conly">Previous Versions:
  <dd class="w3conly"><a href="http://www.w3.org/TR/2011/WD-dom-20110915/">http://www.w3.org/TR/2011/WD-dom-20110915/</a>
  <dd class="w3conly"><a href="http://www.w3.org/TR/2011/WD-domcore-20110531/">http://www.w3.org/TR/2011/WD-domcore-20110531/</a>
  <dd class="w3conly"><a href="http://www.w3.org/TR/2010/WD-domcore-20101007/">http://www.w3.org/TR/2010/WD-domcore-20101007/</a>

  <dt>Editors:
  <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
    (<a href="http://www.opera.com/">Opera Software ASA</a>)
    &lt;<a href="mailto:annevk@opera.com">annevk@opera.com</a>&gt;
  <dd>Aryeh Gregor
   (Google, Inc)
   &lt;<a href="mailto:ayg@aryeh.name">ayg@aryeh.name</a>&gt;
  <dd>Ms2ger (<a href="http://www.mozilla.org/">Mozilla Foundation</a>)
    &lt;<a href="mailto:ms2ger@gmail.com">ms2ger@gmail.com</a>&gt;
 </dl>

<div class="publish">
<!--begin-copyright-->
<p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 2012 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>&reg;</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>
<!--end-copyright--></div>

<hr class="top">

<div class="publish">
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>DOM4 defines the event and document model the Web platform uses. The
DOM is a language- and platform neutral interface that allows programs and
scripts to dynamically access and update the content and structure of
documents.



<h2 class="no-num no-toc" id="status-of-this-document"><span id="sotd">Status of this Document</span></h2>
<p><i>This section describes the status of this document at the time of its
publication. Other documents may supersede this document. A list of current W3C
publications and the latest revision of this technical report can be found in
the <a href="http://www.w3.org/TR/">W3C technical reports index</a> at
http://www.w3.org/TR/.</i>

<p>This is the 5 January 2012 W3C Working Draft of DOM4. Please send
comments to
<a href="mailto:www-dom@w3.org?subject=%5BDOM%5D%20">www-dom@w3.org</a>
(<a href="http://lists.w3.org/Archives/Public/www-dom/">archived</a>)
with <samp>[DOM]</samp> at the start of the subject line, or
<a href="http://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&amp;component=DOM">file a bug</a>.

<p>This document is produced by the
<a href="http://www.w3.org/2008/webapps/">Web Applications</a> (WebApps) Working
Group. The WebApps Working Group is part of the
<a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a> in
the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.

<p>This document was produced by a group operating under the
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004
W3C Patent Policy</a>. W3C maintains a
<a href="http://www.w3.org/2004/01/pp-impl/42538/status" rel="disclosure">public
list of any patent disclosures</a> made in connection with the deliverables of
the group; that page also includes instructions for disclosing a patent. An
individual who has actual knowledge of a patent which the individual believes
contains
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with
<a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.

<p>Publication as a Working Draft does not imply endorsement by the W3C
Membership. This is a draft document and may be updated, replaced or
obsoleted by other documents at any time. It is inappropriate to cite this
document as other than work in progress.
</div>
</div>



<h2 class="no-num no-toc" id="table-of-contents">Table of Contents</h2>

<!--begin-toc-->
<ol class="toc">
 <li><a class="no-num" href="#goals">Goals</a></li>
 <li><a class="no-num" href="#issues">Issues</a></li>
 <li><a href="#conformance"><span class="secno">1 </span>Conformance</a>
  <ol class="toc">
   <li><a href="#dependencies"><span class="secno">1.1 </span>Dependencies</a></li>
   <li><a href="#extensibility"><span class="secno">1.2 </span>Extensibility</a></ol></li>
 <li><a href="#terminology"><span class="secno">2 </span>Terminology</a>
  <ol class="toc">
   <li><a href="#trees"><span class="secno">2.1 </span>Trees</a></li>
   <li><a href="#strings"><span class="secno">2.2 </span>Strings</a></li>
   <li><a href="#common-microsyntaxes"><span class="secno">2.3 </span>Common microsyntaxes</a>
    <ol class="toc">
     <li><a href="#common-parser-idioms"><span class="secno">2.3.1 </span>Common parser idioms</a></li>
     <li><a href="#space-separated-tokens"><span class="secno">2.3.2 </span>Space-separated tokens</a></ol></li>
   <li><a href="#namespaces"><span class="secno">2.4 </span>Namespaces</a></ol></li>
 <li><a href="#errors"><span class="secno">3 </span>Errors</a>
  <ol class="toc">
   <li><a href="#exception-domexception"><span class="secno">3.1 </span>Exception <code>DOMException</code></a></li>
   <li><a href="#interface-domerror"><span class="secno">3.2 </span>Interface <code>DOMError</code></a></ol></li>
 <li><a href="#events"><span class="secno">4 </span>Events</a>
  <ol class="toc">
   <li><a href="#interface-event"><span class="secno">4.1 </span>Interface <code>Event</code></a></li>
   <li><a href="#interface-customevent"><span class="secno">4.2 </span>Interface <code>CustomEvent</code></a></li>
   <li><a href="#constructing-events"><span class="secno">4.3 </span>Constructing events</a></li>
   <li><a href="#interface-eventtarget"><span class="secno">4.4 </span>Interface <code>EventTarget</code></a></li>
   <li><a href="#dispatching-events"><span class="secno">4.5 </span>Dispatching events</a></li>
   <li><a href="#firing-events"><span class="secno">4.6 </span>Firing events</a></ol></li>
 <li><a href="#nodes"><span class="secno">5 </span>Nodes</a>
  <ol class="toc">
   <li><a href="#node-tree"><span class="secno">5.1 </span>Node tree</a>
    <ol class="toc">
     <li><a href="#mutation-algorithms"><span class="secno">5.1.1 </span>Mutation algorithms</a></li>
     <li><a href="#mutation-methods"><span class="secno">5.1.2 </span>Mutation methods</a></li>
     <li><a href="#legacy-mutation-methods"><span class="secno">5.1.3 </span>Legacy mutation methods</a></li>
     <li><a href="#mutation-observers"><span class="secno">5.1.4 </span>Mutation observers</a></ol></li>
   <li><a href="#interface-node"><span class="secno">5.2 </span>Interface <code>Node</code></a></li>
   <li><a href="#interface-document"><span class="secno">5.3 </span>Interface <code>Document</code></a>
    <ol class="toc">
     <li><a href="#interface-domimplementation"><span class="secno">5.3.1 </span>Interface <code>DOMImplementation</code></a></ol></li>
   <li><a href="#interface-documentfragment"><span class="secno">5.4 </span>Interface <code>DocumentFragment</code></a></li>
   <li><a href="#interface-documenttype"><span class="secno">5.5 </span>Interface <code>DocumentType</code></a></li>
   <li><a href="#interface-element"><span class="secno">5.6 </span>Interface <code>Element</code></a>
    <ol class="toc">
     <li><a href="#interface-attr"><span class="secno">5.6.1 </span>Interface <code>Attr</code></a></ol></li>
   <li><a href="#interface-characterdata"><span class="secno">5.7 </span>Interface <code>CharacterData</code></a></li>
   <li><a href="#interface-text"><span class="secno">5.8 </span>Interface <code>Text</code></a></li>
   <li><a href="#interface-processinginstruction"><span class="secno">5.9 </span>Interface <code>ProcessingInstruction</code></a></li>
   <li><a href="#interface-comment"><span class="secno">5.10 </span>Interface <code>Comment</code></a></ol></li>
 <li><a href="#ranges"><span class="secno">6 </span>Ranges</a>
  <ol class="toc">
   <li><a href="#interface-range"><span class="secno">6.1 </span>Interface <code>Range</code></a></ol></li>
 <li><a href="#traversal"><span class="secno">7 </span>Traversal</a>
  <ol class="toc">
   <li><a href="#interface-nodeiterator"><span class="secno">7.1 </span>Interface <code>NodeIterator</code></a></li>
   <li><a href="#interface-treewalker"><span class="secno">7.2 </span>Interface <code>TreeWalker</code></a></li>
   <li><a href="#interface-nodefilter"><span class="secno">7.3 </span>Interface <code>NodeFilter</code></a></ol></li>
 <li><a href="#collections"><span class="secno">8 </span>Collections</a>
  <ol class="toc">
   <li><a href="#interface-nodelist"><span class="secno">8.1 </span>Interface <code>NodeList</code></a></li>
   <li><a href="#interface-htmlcollection"><span class="secno">8.2 </span>Interface <code>HTMLCollection</code></a></ol></li>
 <li><a href="#lists"><span class="secno">9 </span>Lists</a>
  <ol class="toc">
   <li><a href="#interface-domstringlist"><span class="secno">9.1 </span>Interface <code>DOMStringList</code></a></li>
   <li><a href="#interface-domtokenlist"><span class="secno">9.2 </span>Interface <code>DOMTokenList</code></a></li>
   <li><a href="#interface-domsettabletokenlist"><span class="secno">9.3 </span>Interface <code>DOMSettableTokenList</code></a></ol></li>
 <li><a href="#dom-features"><span class="secno">10 </span>DOM features</a></li>
 <li><a href="#historical"><span class="secno">11 </span>Historical</a>
  <ol class="toc">
   <li><a href="#dom-events"><span class="secno">11.1 </span>DOM Events</a></li>
   <li><a href="#dom-core"><span class="secno">11.2 </span>DOM Core</a></li>
   <li><a href="#dom-range"><span class="secno">11.3 </span>DOM Range</a></li>
   <li><a href="#dom-traversal"><span class="secno">11.4 </span>DOM Traversal</a></ol></li>
 <li><a class="no-num" href="#references">References</a>
  <ol class="toc">
   <li><a class="no-num" href="#normative-references">Normative references</a></li>
   <li><a class="no-num" href="#informative-references">Informative references</a></ol></li>
 <li><a class="no-num" href="#acknowledgments">Acknowledgments</a></ol>
<!--end-toc-->



<h2 class="no-num" id="goals">Goals</h2>

<p>This specification standardizes the DOM. It does so as follows:</p>

<ol>
 <li>
  <p>By consolidating <cite>DOM Level 3 Core</cite>
  <a class="informative" href="#refsDOM3CORE">[DOM3CORE]</a>,
  <cite>Element Traversal</cite>
  <a class="informative" href="#refsELEMENTTRAVERSAL">[ELEMENTTRAVERSAL]</a>, the
  "DOM Event Architecture" and "Basic Event Interfaces" chapters of
  <cite>DOM Level 3 Events</cite>
  <a class="informative" href="#refsDOM3EVENTS">[DOM3EVENTS]</a> (specific type
  of events do not belong in the base specification), and
  <cite>DOM Level 2 Traversal and Range</cite>
  <a class="informative" href="#refsDOM2TR">[DOM2TR]</a>, and:

  <ul>
   <li>Aligning them with the needs of ECMAScript where possible.
   <li>Aligning them with existing implementations.
   <li>Simplifying them as much as possible.
  </ul>

 <li><p>By moving features from HTML5 that ought to be part of the DOM
 platform here, while preventing a dependency on HTML5.
 <a class="informative" href="#refsHTML">[HTML]</a>

 <li>
  <p>By defining a replacement for the "Mutation Events"
  "Mutation Name Event Types" chapters of <cite>DOM Level 3 Events</cite>
  <a class="informative" href="#refsDOM3EVENTS">[DOM3EVENTS]</a> as the old model
  was problematic.

  <p class="note">The old model is expected to be removed from implementations
  in due course.

 <li><p>By defining new features that simplify common DOM operations.
</ol>




<h2 class="no-num" id="issues">Issues</h2>

<ul class="XXX">
 <li><a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13040">Mutation listeners</a> (and updating the methods that mutate)
 <li>Define event handlers. Define list of event handler IDL attributes? Define a concept for event handler content attributes?
 <li>Move DOMStringMap here?
</ul>

<!--
 In the "would be nice" department:

 * Section explaining how to define new events

 * Alternative way of doing concept-node-insert and concept-node-remove for
   ranges: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-March/031053.html
-->


<h2 id="conformance"><span class="secno">1 </span>Conformance</h2>
<p>All diagrams, examples, and notes in this specification are
non-normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative.

<p>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" in the normative parts of this document are to be
interpreted as described in RFC2119. For readability, these words do
not appear in all uppercase letters in this specification. <a href="#refsRFC2119">[RFC2119]</a>

<p>Requirements phrased in the imperative as part of algorithms
(such as "strip any leading space characters" or "return false and
terminate these steps") are to be interpreted with the meaning of the
key word ("must", "should", "may", etc) used in introducing the
algorithm.

<p>Conformance requirements phrased as algorithms or specific steps
may be implemented in any manner, so long as the end result is
equivalent. (In particular, the algorithms defined in this
specification are intended to be easy to follow, and not intended to
be performant.)

<p id="hardwareLimitations">User agents may impose
implementation-specific limits on otherwise unconstrained inputs,
e.g. to prevent denial of service attacks, to guard against running
out of memory, or to work around platform-specific limitations.

<p>When a method or an attribute is said to call another method or attribute, the user agent must invoke its internal API for that attribute or method so that e.g. the author can't change the behavior by overriding attributes or methods with custom properties or functions in ECMAScript.

<p>Unless otherwise stated, string comparisons are done in a <a href="#case-sensitive">case-sensitive</a> manner.

<h3 id="dependencies"><span class="secno">1.1 </span>Dependencies</h3>

<p>The IDL fragments in this specification must be interpreted as
required for conforming IDL fragments, as described in the Web IDL
specification. <a href="#refsWEBIDL">[WEBIDL]</a>

<p>Some of the terms used in this specification are defined in
<cite>Web IDL</cite>, <cite>XML</cite> and <cite>Namespaces in XML</cite>.
<a href="#refsWEBIDL">[WEBIDL]</a>
<a href="#refsXML">[XML]</a>
<a href="#refsXMLNS">[XMLNS]</a>

<h3 id="extensibility"><span class="secno">1.2 </span>Extensibility</h3>

<p>Vendor-specific proprietary extensions to this specification are
strongly discouraged. Authors must not use such extensions, as
doing so reduces interoperability and fragments the user base,
allowing only users of specific user agents to access the content in
question.

<p>If vendor-specific extensions are needed, the members should be
prefixed by vendor-specific strings to prevent clashes with future
versions of this specification. Extensions must be defined so that
the use of extensions neither contradicts nor causes the
non-conformance of functionality defined in the specification.
<!-- thanks to QA Framework -->

<p>When vendor-neutral extensions to this specification are needed,
either this specification can be updated accordingly, or an
extension specification can be written that overrides the
requirements in this specification. When someone applying this
specification to their activities decides that they will recognize
the requirements of such an extension specification, it becomes an
<dfn id="other-applicable-specifications" title="other applicable specifications">applicable
specification</dfn> for the purposes of conformance requirements in
this specification.
<!-- http://www.w3.org/mid/17E341CD-E790-422C-9F9A-69347EE01CEB@iki.fi -->


<h2 id="terminology"><span class="secno">2 </span>Terminology</h2>

<p>The term <dfn id="context-object">context object</dfn> means the object on which the method
or attribute being discussed was called. When the
<a href="#context-object">context object</a> is unambiguous, the term can be omitted.

<!-- XXX we should prolly explain that "set attribute X to Y" works even for
readonly attributes when it is language for implementors -->

<p>The <dfn id="preferred-mime-name">preferred MIME name</dfn> of a
character encoding is the name or alias labeled as "preferred MIME name" in
the IANA <cite>Character Sets</cite> registry, if there is one, or the
encoding's name, if none of the aliases are so labeled.
<a href="#refsIANACHARSET">[IANACHARSET]</a>
<!-- copied from HTML -->

<h3 id="trees"><span class="secno">2.1 </span>Trees</h3> <!-- Sorry reddit, this is not /r/trees -->

<p>Just like most programming paradigms the Web platform has finite
hierarchical tree structures, simply named
<dfn id="concept-tree" title="concept-tree">trees</dfn>. The
<dfn id="concept-tree-order" title="concept-tree-order">tree order</dfn> is preorder, depth-first
traversal.
<!-- http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_Traversal -->

<p>An object that <dfn id="concept-tree-participate" title="concept-tree-participate">participates</dfn> in
a <a href="#concept-tree" title="concept-tree">tree</a> has a
<dfn id="concept-tree-parent" title="concept-tree-parent">parent</dfn>, which is either another object
or null, and an ordered list of zero or more
<dfn id="concept-tree-child" title="concept-tree-child">child</dfn> objects.

<p>The <dfn id="concept-tree-root" title="concept-tree-root">root</dfn> of an object is itself, if it
has no <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, or else it is the
<a href="#concept-tree-root" title="concept-tree-root">root</a> of its
<a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

<p>An object <var title="">A</var> is called a
<dfn id="concept-tree-descendant" title="concept-tree-descendant">descendant</dfn> of an object
<var title="">B</var>, if either <var title="">A</var> is a
<a href="#concept-tree-child" title="concept-tree-child">child</a> of <var title="">B</var> or
<var title="">A</var> is a <a href="#concept-tree-child" title="concept-tree-child">child</a> of an
object <var title="">C</var> that is a
<a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of <var title="">B</var>.

<p>An
<dfn id="concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</dfn> is
an object or one of its
<a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a>.

<p>An object <var title="">A</var> is called an
<dfn id="concept-tree-ancestor" title="concept-tree-ancestor">ancestor</dfn> of an object
<var title="">B</var> if and only if <var title="">B</var> is a
<a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
<var title="">A</var>.

<p>An <dfn id="concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</dfn> is
an object or one of its <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a>.

<p>An object <var title="">A</var> is called a
<dfn id="concept-tree-sibling" title="concept-tree-sibling">sibling</dfn> of an object
<var title="">B</var>, if and only if <var title="">B</var> and <var title="">A</var>
share the same non-null <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

<p>An object <var title="">A</var> is
<dfn id="concept-tree-preceding" title="concept-tree-preceding">preceding</dfn> an object
<var title="">B</var> if <var title="">A</var> and <var title="">B</var> are in the
same <a href="#concept-tree" title="concept-tree">tree</a> and <var title="">A</var> comes
before <var title="">B</var> in
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

<p>An object <var title="">A</var> is
<dfn id="concept-tree-following" title="concept-tree-following">following</dfn> an object
<var title="">B</var> if <var title="">A</var> and <var title="">B</var> are in the
same <a href="#concept-tree" title="concept-tree">tree</a> and <var title="">A</var> comes
after <var title="">B</var> in
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

<p>The <dfn id="concept-tree-first-child" title="concept-tree-first-child">first child</dfn> of an object is
its first <a href="#concept-tree-child" title="concept-tree-child">child</a> or null if it has no
<a href="#concept-tree-child" title="concept-tree-child">child</a>.

<p>The <dfn id="concept-tree-last-child" title="concept-tree-last-child">last child</dfn> of an object is
its last <a href="#concept-tree-child" title="concept-tree-child">child</a> or null if it has no
<a href="#concept-tree-child" title="concept-tree-child">child</a>.

<p>The <dfn id="concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</dfn> of an
object is its first <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> or null if it has no
<a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a>.

<p>The <dfn id="concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</dfn> of an
object is its first <a href="#concept-tree-following" title="concept-tree-following">following</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> or null if it has no
<a href="#concept-tree-following" title="concept-tree-following">following</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a>.

<p>The <dfn id="concept-tree-index" title="concept-tree-index">index</dfn> of an object is its number
of <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">siblings</a>.


<h3 id="strings"><span class="secno">2.2 </span>Strings</h3>
<p>Comparing two strings in a <dfn id="case-sensitive">case-sensitive</dfn> manner means comparing them exactly, code point for code point.

<p>Comparing two strings in a <dfn id="ascii-case-insensitive">ASCII case-insensitive</dfn> manner means comparing them exactly, code point for code point, except that the characters in the range U+0041 .. U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) and the corresponding characters in the range U+0061 .. U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) are considered to also match.

<p><dfn id="converted-to-ascii-uppercase" title="converted to ascii uppercase">Converting a string to ASCII uppercase</dfn> means replacing all characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z) with the corresponding characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z).

<p><dfn id="converted-to-ascii-lowercase" title="converted to ascii lowercase">Converting a string to ASCII lowercase</dfn> means replacing all characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) with the corresponding characters in the range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL LETTER Z).

<p>A string <var title="">pattern</var> is a <dfn id="prefix-match">prefix match</dfn> for a string
<var title="">s</var> when <var title="">pattern</var> is not longer than
<var title="">s</var> and truncating <var title="">s</var> to
<var title="">pattern</var>'s length leaves the two strings as matches of each
other.

<p>The <dfn id="space-character" title="space character">space characters</dfn>, for the
purposes of this specification, are U+0020 SPACE, U+0009 CHARACTER
TABULATION (tab), U+000A LINE FEED (LF), U+000C FORM FEED (FF), and
U+000D CARRIAGE RETURN (CR).


<h3 id="common-microsyntaxes"><span class="secno">2.3 </span>Common microsyntaxes</h3>
<h4 id="common-parser-idioms"><span class="secno">2.3.1 </span>Common parser idioms</h4>
<p>Some of the micro-parsers described below follow the pattern of having an
<var title="">input</var> variable that holds the string being parsed, and having a
<var title="">position</var> variable pointing at the next character to parse in
<var title="">input</var>.

<p>For parsers based on this pattern, a step that requires the user agent to
<dfn id="collect-a-sequence-of-characters">collect a sequence of characters</dfn> means that the following algorithm
must be run, with <var title="">characters</var> being the set of characters that
can be collected:

<ol>
 <li><p>Let <var title="">input</var> and <var title="">position</var> be the same
 variables as those of the same name in the algorithm that invoked these steps.

 <li><p>Let <var title="">result</var> be the empty string.

 <li><p>While <var title="">position</var> does not point past the end of
 <var title="">input</var> and the character at <var title="">position</var> is one of
 the <var title="">characters</var>, append that character to the end of
 <var title="">result</var> and advance <var title="">position</var> to the next
 character in <var title="">input</var>.

 <li><p>Return <var title="">result</var>.
</ol>

<p>The step <dfn id="skip-whitespace">skip whitespace</dfn> means that the user agent
must <a href="#collect-a-sequence-of-characters">collect a sequence of characters</a> that are <a href="#space-character" title="space character">space characters</a>. The collected
characters are not used.

<h4 id="space-separated-tokens"><span class="secno">2.3.2 </span>Space-separated tokens</h4>

<p>A <dfn id="set-of-space-separated-tokens">set of space-separated tokens</dfn> is a string containing
zero or more words (known as tokens) separated by one or more <a href="#space-character" title="space character">space characters</a>, where words consist
of any string of one or more characters, none of which are <a href="#space-character" title="space character">space characters</a>.

<p>A string containing a <a href="#set-of-space-separated-tokens">set of space-separated tokens</a>
may have leading or trailing <a href="#space-character" title="space character">space
characters</a>.

<p>An <dfn id="unordered-set-of-unique-space-separated-tokens">unordered set of unique space-separated tokens</dfn> is a
<a href="#set-of-space-separated-tokens">set of space-separated tokens</a> where none of the tokens
are duplicated.

<p>An <dfn id="ordered-set-of-unique-space-separated-tokens">ordered set of unique space-separated tokens</dfn> is a
<a href="#set-of-space-separated-tokens">set of space-separated tokens</a> where none of the tokens
are duplicated but where the order of the tokens is meaningful.

<p><a href="#set-of-space-separated-tokens" title="set of space-separated tokens">Sets of
space-separated tokens</a> sometimes have a defined set of
allowed values. When a set of allowed values is defined, the tokens
must all be from that list of allowed values; other values are
non-conforming. If no such set of allowed values is provided, then
all values are conforming.

<p class="note">How tokens in a <a href="#set-of-space-separated-tokens">set of space-separated
tokens</a> are to be compared (e.g. case-sensitively or not) is
defined on a per-set basis.

<div class="impl">

<p>When a user agent has to <dfn id="split-a-string-on-spaces">split a string on spaces</dfn>, it
must use the following algorithm:

<ol>
 <li><p>Let <var title="">input</var> be the string being parsed.

 <li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>,
 initially pointing at the start of the string.

 <li><p>Let <var title="">tokens</var> be a list of tokens, initially empty.

 <li><p><a href="#skip-whitespace">Skip whitespace</a>.

 <li><p>While <var title="">position</var> is not past the end of
 <var title="">input</var>:

  <ol>
   <li><p><a href="#collect-a-sequence-of-characters">Collect a sequence of characters</a> that are not
   <a href="#space-character" title="space character">space characters</a>.

   <li><p>Add the string collected in the previous step to
   <var title="">tokens</var>.

   <li><p><a href="#skip-whitespace">Skip whitespace</a>.
  </ol>

 <li><p>Return <var title="">tokens</var>.
</ol>

<p>When a user agent has to <dfn id="remove-a-token-from-a-string">remove a token from a string</dfn>,
it must use the following algorithm:

<ol>
 <li><p>Let <var title="">input</var> be the string being modified.

 <li><p>Let <var title="">token</var> be the token being removed. It will not
 contain any <a href="#space-character" title="space character">space characters</a>.

 <li><p>Let <var title="">output</var> be the output string, initially empty.

 <li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>,
 initially pointing at the start of the string.

 <li><p><i title="">Loop</i>: If <var title="">position</var> is beyond the end of
 <var title="">input</var>, terminate these steps.

 <li>
  <p>If the character at <var title="">position</var> is a <a href="#space-character">space
  character</a>:

  <ol>
   <li><p>Append the character at <var title="">position</var> to the end of <var title="">output</var>.

   <li><p>Advance <var title="">position</var> so it points at the next character
   in <var title="">input</var>.

   <li><p>Return to the step labeled <i title="">loop</i>.
  </ol>

 <li><p>Otherwise, the character at <var title="">position</var> is the first
 character of a token. <a href="#collect-a-sequence-of-characters">Collect a sequence of characters</a> that are
 not <a href="#space-character" title="space character">space characters</a>, and let that be <var title="">s</var>.

 <li>
  <p>If <var title="">s</var> is exactly equal to <var title="">token</var>, then:

  <ol>
   <li><p><a href="#skip-whitespace">Skip whitespace</a> (in <var title="">input</var>).

   <li><p>Remove any <a href="#space-character" title="space character">space characters</a>
   currently at the end of <var title="">output</var>.

   <li><p>If <var title="">position</var> is not past the end of <var title="">input</var>, and <var title="">output</var> is not the empty string,
   append a single U+0020 SPACE character at the end of <var title="">output</var>.
  </ol>

 <li><p>Otherwise, append <var title="">s</var> to the end of <var title="">output</var>.

 <li><p>Return to the step labeled <i title="">loop</i>.
</ol>

<p class="note">This causes any occurrences of the token to be
removed from the string, and any spaces that were surrounding the
token to be collapsed to a single space, except at the start and end
of the string, where such spaces are removed.

</div>


<h3 id="namespaces"><span class="secno">2.4 </span>Namespaces</h3>
<p>The <dfn id="html-namespace">HTML namespace</dfn> is <code title="">http://www.w3.org/1999/xhtml</code>.

<p>The <dfn id="xml-namespace">XML namespace</dfn> is <code title="">http://www.w3.org/XML/1998/namespace</code>.

<p>The <dfn id="xmlns-namespace">XMLNS namespace</dfn> is <code title="">http://www.w3.org/2000/xmlns/</code>.


<h2 id="errors"><span class="secno">3 </span>Errors</h2>
<h3 id="exception-domexception"><span class="secno">3.1 </span>Exception <code><a href="#domexception">DOMException</a></code></h3>
<pre class="idl">exception <dfn id="domexception">DOMException</dfn> {
  const unsigned short <a href="#dom-domexception-index_size_err" title="dom-DOMException-INDEX_SIZE_ERR">INDEX_SIZE_ERR</a> = 1;
  const unsigned short <span title="dom-DOMException-DOMSTRING_SIZE_ERR">DOMSTRING_SIZE_ERR</span> = 2; // historical
  const unsigned short <a href="#dom-domexception-hierarchy_request_err" title="dom-DOMException-HIERARCHY_REQUEST_ERR">HIERARCHY_REQUEST_ERR</a> = 3;
  const unsigned short <a href="#dom-domexception-wrong_document_err" title="dom-DOMException-WRONG_DOCUMENT_ERR">WRONG_DOCUMENT_ERR</a> = 4;
  const unsigned short <a href="#dom-domexception-invalid_character_err" title="dom-DOMException-INVALID_CHARACTER_ERR">INVALID_CHARACTER_ERR</a> = 5;
  const unsigned short <span title="dom-DOMException-NO_DATA_ALLOWED_ERR">NO_DATA_ALLOWED_ERR</span> = 6; // historical
  const unsigned short <a href="#dom-domexception-no_modification_allowed_err" title="dom-DOMException-NO_MODIFICATION_ALLOWED_ERR">NO_MODIFICATION_ALLOWED_ERR</a> = 7;
  const unsigned short <a href="#dom-domexception-not_found_err" title="dom-DOMException-NOT_FOUND_ERR">NOT_FOUND_ERR</a> = 8;
  const unsigned short <a href="#dom-domexception-not_supported_err" title="dom-DOMException-NOT_SUPPORTED_ERR">NOT_SUPPORTED_ERR</a> = 9;
  const unsigned short <span title="dom-DOMException-INUSE_ATTRIBUTE_ERR">INUSE_ATTRIBUTE_ERR</span> = 10; // historical
  const unsigned short <a href="#dom-domexception-invalid_state_err" title="dom-DOMException-INVALID_STATE_ERR">INVALID_STATE_ERR</a> = 11;
  const unsigned short <a href="#dom-domexception-syntax_err" title="dom-DOMException-SYNTAX_ERR">SYNTAX_ERR</a> = 12;
  const unsigned short <a href="#dom-domexception-invalid_modification_err" title="dom-DOMException-INVALID_MODIFICATION_ERR">INVALID_MODIFICATION_ERR</a> = 13;
  const unsigned short <a href="#dom-domexception-namespace_err" title="dom-DOMException-NAMESPACE_ERR">NAMESPACE_ERR</a> = 14;
  const unsigned short <a href="#dom-domexception-invalid_access_err" title="dom-DOMException-INVALID_ACCESS_ERR">INVALID_ACCESS_ERR</a> = 15;
  const unsigned short <span title="dom-DOMException-VALIDATION_ERR">VALIDATION_ERR</span> = 16; // historical
  const unsigned short <a href="#dom-domexception-type_mismatch_err" title="dom-DOMException-TYPE_MISMATCH_ERR">TYPE_MISMATCH_ERR</a> = 17;
  const unsigned short <a href="#dom-domexception-security_err" title="dom-DOMException-SECURITY_ERR">SECURITY_ERR</a> = 18;
  const unsigned short <a href="#dom-domexception-network_err" title="dom-DOMException-NETWORK_ERR">NETWORK_ERR</a> = 19;
  const unsigned short <a href="#dom-domexception-abort_err" title="dom-DOMException-ABORT_ERR">ABORT_ERR</a> = 20;
  const unsigned short <a href="#dom-domexception-url_mismatch_err" title="dom-DOMException-URL_MISMATCH_ERR">URL_MISMATCH_ERR</a> = 21;
  const unsigned short <a href="#dom-domexception-quota_exceeded_err" title="dom-DOMException-QUOTA_EXCEEDED_ERR">QUOTA_EXCEEDED_ERR</a> = 22;
  const unsigned short <a href="#dom-domexception-timeout_err" title="dom-DOMException-TIMEOUT_ERR">TIMEOUT_ERR</a> = 23;
  const unsigned short <a href="#dom-domexception-invalid_node_type_err" title="dom-DOMException-INVALID_NODE_TYPE_ERR">INVALID_NODE_TYPE_ERR</a> = 24;
  const unsigned short <a href="#dom-domexception-data_clone_err" title="dom-DOMException-DATA_CLONE_ERR">DATA_CLONE_ERR</a> = 25;
  unsigned short <a href="#dom-domexception-code" title="dom-DOMException-code">code</a>;
};</pre>

<p>The <dfn id="dom-domexception-code" title="dom-DOMException-code"><code>code</code></dfn> exception
field must return the value it was initialized to. When an exception is
created it must be initialized to zero.

<p>To <dfn id="concept-throw" title="concept-throw">throw</dfn> a <var title="">type</var> exception
these steps must be run:

<ol>
 <li><p>Create a new <code><a href="#domexception">DOMException</a></code> exception whose
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-type">type</a> is <var title="">type</var>.

 <li><p>Set its <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-message">message</a> to a
 user agent-defined value.

 <li><p>If its <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-type">type</a> is in the first column of the table below and has a corresponding legacy
 <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value in the
 third column, set its <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code>
 exception field to that value.

 <li><p><a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-throw">Throw</a> the exception.
</ol>

<p class="example">To
<i title="">throw a "<code><a href="#timeouterror">TimeoutError</a></code>" exception</i>, a
user agent would construct a <code><a href="#domexception">DOMException</a></code> exception whose
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-exception-type">type</a> is
"<code><a href="#timeouterror">TimeoutError</a></code>" and
<code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value is 23,
and actually throw that object as an exception.

<table id="error-types">
 <thead>
 <tr><th>Type<th>Description<th>Legacy <code title="dom-DOMException-code"><a href="#dom-domexception-code">code</a></code> exception field value (if any)
 <tbody>
 <tr>
  <td>"<dfn id="indexsizeerror"><code>IndexSizeError</code></dfn>"
  <td>The index is not in the allowed range.
  <td><dfn id="dom-domexception-index_size_err" title="dom-DOMException-INDEX_SIZE_ERR"><code>INDEX_SIZE_ERR</code></dfn> (1)
 <tr>
  <td>"<dfn id="hierarchyrequesterror"><code>HierarchyRequestError</code></dfn>"
  <td>The operation would yield an incorrect <a href="#node-tree">node tree</a>.
  <td><dfn id="dom-domexception-hierarchy_request_err" title="dom-DOMException-HIERARCHY_REQUEST_ERR"><code>HIERARCHY_REQUEST_ERR</code></dfn> (3)
 <tr>
  <td>"<dfn id="wrongdocumenterror"><code>WrongDocumentError</code></dfn>"
  <td>The object is in the wrong <a href="#concept-document" title="concept-document">document</a>.
  <td><dfn id="dom-domexception-wrong_document_err" title="dom-DOMException-WRONG_DOCUMENT_ERR"><code>WRONG_DOCUMENT_ERR</code></dfn> (4)
 <tr>
  <td>"<dfn id="invalidcharactererror"><code>InvalidCharacterError</code></dfn>"
  <td>The string contains invalid characters.
  <td><dfn id="dom-domexception-invalid_character_err" title="dom-DOMException-INVALID_CHARACTER_ERR"><code>INVALID_CHARACTER_ERR</code></dfn> (5)
 <tr>
  <td>"<dfn id="nomodificationallowederror"><code>NoModificationAllowedError</code></dfn>"
  <td>The object can not be modified.
  <td><dfn id="dom-domexception-no_modification_allowed_err" title="dom-DOMException-NO_MODIFICATION_ALLOWED_ERR"><code>NO_MODIFICATION_ALLOWED_ERR</code></dfn> (7)
 <tr>
  <td>"<dfn id="notfounderror"><code>NotFoundError</code></dfn>"
  <td>The object can not be found here.
  <td><dfn id="dom-domexception-not_found_err" title="dom-DOMException-NOT_FOUND_ERR"><code>NOT_FOUND_ERR</code></dfn> (8)
 <tr>
  <td>"<dfn id="notsupportederror"><code>NotSupportedError</code></dfn>"
  <td>The operation is not supported.
  <td><dfn id="dom-domexception-not_supported_err" title="dom-DOMException-NOT_SUPPORTED_ERR"><code>NOT_SUPPORTED_ERR</code></dfn> (9)
 <tr>
  <td>"<dfn id="invalidstateerror"><code>InvalidStateError</code></dfn>"
  <td>The object is in an invalid state.
  <td><dfn id="dom-domexception-invalid_state_err" title="dom-DOMException-INVALID_STATE_ERR"><code>INVALID_STATE_ERR</code></dfn> (11)
 <tr>
  <td>"<dfn id="syntaxerror"><code>SyntaxError</code></dfn>"
  <td>The string did not match the expected pattern.
  <td><dfn id="dom-domexception-syntax_err" title="dom-DOMException-SYNTAX_ERR"><code>SYNTAX_ERR</code></dfn> (12)
 <tr>
  <td>"<dfn id="invalidmodificationerror"><code>InvalidModificationError</code></dfn>"
  <td>The object can not be modified in this way.
  <td><dfn id="dom-domexception-invalid_modification_err" title="dom-DOMException-INVALID_MODIFICATION_ERR"><code>INVALID_MODIFICATION_ERR</code></dfn> (13)
 <tr>
  <td>"<dfn id="namespaceerror"><code>NamespaceError</code></dfn>"
  <td>The operation is not allowed by <cite>Namespaces in XML</cite>. <a href="#refsXMLNS">[XMLNS]</a>
  <td><dfn id="dom-domexception-namespace_err" title="dom-DOMException-NAMESPACE_ERR"><code>NAMESPACE_ERR</code></dfn> (14)
 <tr>
  <td>"<dfn id="invalidaccesserror"><code>InvalidAccessError</code></dfn>"
  <td>The object does not support the operation or argument.
  <td><dfn id="dom-domexception-invalid_access_err" title="dom-DOMException-INVALID_ACCESS_ERR"><code>INVALID_ACCESS_ERR</code></dfn> (15)
 <tr>
  <td>"<dfn id="typemismatcherror"><code>TypeMismatchError</code></dfn>"
  <td>The type of the object does not match the expected type.
  <td><dfn id="dom-domexception-type_mismatch_err" title="dom-DOMException-TYPE_MISMATCH_ERR"><code>TYPE_MISMATCH_ERR</code></dfn> (17)
 <tr>
  <!-- XHR -->
  <td>"<dfn id="securityerror"><code>SecurityError</code></dfn>"
  <td>The operation is insecure.
  <td><dfn id="dom-domexception-security_err" title="dom-DOMException-SECURITY_ERR"><code>SECURITY_ERR</code></dfn> (18)
 <tr>
  <!-- XHR -->
  <td>"<dfn id="networkerror"><code>NetworkError</code></dfn>"
  <td>A network error occurred.
  <td><dfn id="dom-domexception-network_err" title="dom-DOMException-NETWORK_ERR"><code>NETWORK_ERR</code></dfn> (19)
 <tr>
  <!-- XHR -->
  <td>"<dfn id="aborterror"><code>AbortError</code></dfn>"
  <td>The operation was aborted.
  <td><dfn id="dom-domexception-abort_err" title="dom-DOMException-ABORT_ERR"><code>ABORT_ERR</code></dfn> (20)
 <tr>
  <!-- Workers -->
  <td>"<dfn id="urlmismatcherror"><code>URLMismatchError</code></dfn>"
  <td>The given URL does not match another URL.
  <td><dfn id="dom-domexception-url_mismatch_err" title="dom-DOMException-URL_MISMATCH_ERR"><code>URL_MISMATCH_ERR</code></dfn> (21)
 <tr>
  <!-- HTML -->
  <td>"<dfn id="quotaexceedederror"><code>QuotaExceededError</code></dfn>"
  <td>The quota has been exceeded.
  <td><dfn id="dom-domexception-quota_exceeded_err" title="dom-DOMException-QUOTA_EXCEEDED_ERR"><code>QUOTA_EXCEEDED_ERR</code></dfn> (22)
 <tr>
  <!-- XHR -->
  <td>"<dfn id="timeouterror"><code>TimeoutError</code></dfn>"
  <td>The operation timed out.
  <td><dfn id="dom-domexception-timeout_err" title="dom-DOMException-TIMEOUT_ERR"><code>TIMEOUT_ERR</code></dfn> (23)
 <tr>
  <td>"<dfn id="invalidnodetypeerror"><code>InvalidNodeTypeError</code></dfn>"
  <td>The supplied node is incorrect or has an incorrect ancestor for this operation.
  <td><dfn id="dom-domexception-invalid_node_type_err" title="dom-DOMException-INVALID_NODE_TYPE_ERR"><code>INVALID_NODE_TYPE_ERR</code></dfn> (24)
 <tr>
  <!-- HTML -->
  <td>"<dfn id="datacloneerror"><code>DataCloneError</code></dfn>"
  <td>The object can not be cloned.
  <td><dfn id="dom-domexception-data_clone_err" title="dom-DOMException-DATA_CLONE_ERR"><code>DATA_CLONE_ERR</code></dfn> (25)
</table>

<!-- XXX Should we have central bookkeeping of exceptions someplace? -->


<h3 id="interface-domerror"><span class="secno">3.2 </span>Interface <code><a href="#domerror">DOMError</a></code></h3>

<p class="note">This interface is intended for other specifications that want
to introduce error handling through other means than exceptions. It is
expected that the exception types are reused.

<pre class="idl">interface <dfn id="domerror">DOMError</dfn> {
  readonly attribute DOMString <a href="#dom-domerror-name" title="dom-DOMError-name">name</a>;
};</pre>

<p>The <dfn id="dom-domerror-name" title="dom-DOMError-name"><code>name</code></dfn> attribute must
return the value it was initialized to.

<p>A
<dfn id="concept-domerror" title="concept-DOMError"><var title="">type</var> <code>DOMError</code></dfn>
means a <code><a href="#domerror">DOMError</a></code> object whose
<code title="dom-DOMError-name"><a href="#dom-domerror-name">name</a></code> attribute is initialized to
<var title="">type</var>.

<p class="example">A specification could say that an <code title="">error</code>
attribute must return a
<a href="#concept-domerror" title="concept-DOMError">"<code>SyntaxError</code>" <code>DOMError</code></a>.


<h2 id="events"><span class="secno">4 </span>Events</h2>

<h3 id="interface-event"><span class="secno">4.1 </span>Interface <code><a href="#event">Event</a></code></h3>

<pre class="idl">[Constructor(DOMString <var title="">type</var>, optional <a href="#eventinit">EventInit</a> <var title="">eventInitDict</var>)]
interface <dfn id="event">Event</dfn> {
  readonly attribute DOMString <a href="#dom-event-type" title="dom-Event-type">type</a>;
  readonly attribute <a href="#eventtarget">EventTarget</a>? <a href="#dom-event-target" title="dom-Event-target">target</a>;
  readonly attribute <a href="#eventtarget">EventTarget</a>? <a href="#dom-event-currenttarget" title="dom-Event-currentTarget">currentTarget</a>;

  const unsigned short <a href="#dom-event-capturing_phase" title="dom-Event-CAPTURING_PHASE">CAPTURING_PHASE</a> = 1;
  const unsigned short <a href="#dom-event-at_target" title="dom-Event-AT_TARGET">AT_TARGET</a> = 2;
  const unsigned short <a href="#dom-event-bubbling_phase" title="dom-Event-BUBBLING_PHASE">BUBBLING_PHASE</a> = 3;
  readonly attribute unsigned short <a href="#dom-event-eventphase" title="dom-Event-eventPhase">eventPhase</a>;

  void <a href="#dom-event-stoppropagation" title="dom-Event-stopPropagation">stopPropagation</a>();
  void <a href="#dom-event-stopimmediatepropagation" title="dom-Event-stopImmediatePropagation">stopImmediatePropagation</a>();

  readonly attribute boolean <a href="#dom-event-bubbles" title="dom-Event-bubbles">bubbles</a>;
  readonly attribute boolean <a href="#dom-event-cancelable" title="dom-Event-cancelable">cancelable</a>;
  void <a href="#dom-event-preventdefault" title="dom-Event-preventDefault">preventDefault</a>();
  readonly attribute boolean <a href="#dom-event-defaultprevented" title="dom-Event-defaultPrevented">defaultPrevented</a>;

  readonly attribute boolean <a href="#dom-event-istrusted" title="dom-Event-isTrusted">isTrusted</a>;
  readonly attribute DOMTimeStamp <a href="#dom-event-timestamp" title="dom-Event-timeStamp">timeStamp</a>;

  void <a href="#dom-event-initevent" title="dom-Event-initEvent">initEvent</a>(DOMString <var title="">type</var>, boolean <var title="">bubbles</var>, boolean <var title="">cancelable</var>);
};

dictionary <dfn id="eventinit">EventInit</dfn> {
  boolean <span title="dom-EventInit-bubbles">bubbles</span>;
  boolean <span title="dom-EventInit-cancelable">cancelable</span>;
};</pre>

<p>An <dfn id="concept-event" title="concept-event">event</dfn> allows for signaling that
something has occurred. E.g. that an image has completed downloading. It is
represented by the <code><a href="#event">Event</a></code> interface or an interface that
inherits from the <code><a href="#event">Event</a></code> interface.</p>

<p>The <dfn id="dom-event-type" title="dom-Event-type"><code>type</code></dfn> attribute must
return the value it was initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attribute must be
initialized to the empty string.

<p>The <dfn id="dom-event-target" title="dom-Event-target"><code>target</code></dfn> and
<dfn id="dom-event-currenttarget" title="dom-Event-currentTarget"><code>currentTarget</code></dfn>
attributes must return the values they were initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attributes must be
initialized to null.

<p class="note">The <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> and
<code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> attributes are
initialized to different values while
<a href="#concept-event-dispatch" title="concept-event-dispatch">dispatching</a> the
<a href="#concept-event" title="concept-event">event</a>.

<p>The <dfn id="dom-event-eventphase" title="dom-Event-eventPhase"><code>eventPhase</code></dfn>
attribute must return the value it was initialized to, which must be one of
the following:</p>
<dl>
 <dt><dfn id="dom-event-capturing_phase" title="dom-Event-CAPTURING_PHASE"><code>CAPTURING_PHASE</code></dfn> (numeric value 1)</dt>
 <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> on an object that
 <a href="#concept-tree-participate" title="concept-tree-participate">participates</a> in a
 <a href="#concept-tree" title="concept-tree">tree</a> it will be in this phase before it
 reaches its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
 <dt><dfn id="dom-event-at_target" title="dom-Event-AT_TARGET"><code>AT_TARGET</code></dfn> (numeric value 2)
 <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> it will be in this
 phase on its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
 <dt><dfn id="dom-event-bubbling_phase" title="dom-Event-BUBBLING_PHASE"><code>BUBBLING_PHASE</code></dfn> (numeric value 3)
 <dd><p>When an <a href="#concept-event" title="concept-event">event</a> is
 <a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> on an object that
 <a href="#concept-tree-participate" title="concept-tree-participate">participates</a> in a
 <a href="#concept-tree" title="concept-tree">tree</a> it will be in this phase after it
 reaches its <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value.
</dl>
<p>Initially the attribute must be initialized to
<code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>.

<hr>

<p>Each <a href="#concept-event" title="concept-event">event</a> has the following associated
flags that are all initially unset:</p>
<ul>
 <li><dfn id="stop-propagation-flag">stop propagation flag</dfn>
 <li><dfn id="stop-immediate-propagation-flag">stop immediate propagation flag</dfn>
 <li><dfn id="canceled-flag">canceled flag</dfn>
 <li><dfn id="initialized-flag">initialized flag</dfn>
 <li><dfn id="dispatch-flag">dispatch flag</dfn>
</ul>

<p>When the
<dfn id="dom-event-stoppropagation" title="dom-Event-stopPropagation"><code>stopPropagation()</code></dfn>
method is invoked the <a href="#stop-propagation-flag">stop propagation flag</a> must be set.
<p>When the
<dfn id="dom-event-stopimmediatepropagation" title="dom-Event-stopImmediatePropagation"><code>stopImmediatePropagation()</code></dfn>
method is invoked both the <a href="#stop-propagation-flag">stop propagation flag</a> and
<a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a> must be set.

<p>The <dfn id="dom-event-bubbles" title="dom-Event-bubbles"><code>bubbles</code></dfn> and
<dfn id="dom-event-cancelable" title="dom-Event-cancelable"><code>cancelable</code></dfn> attributes
must return the values they were initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attributes must be
initialized to false.

<p>When the
<dfn id="dom-event-preventdefault" title="dom-Event-preventDefault"><code>preventDefault()</code></dfn>
method is invoked and the <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code>
attribute is true, the <a href="#canceled-flag">canceled flag</a> must be set.

<p>The <dfn id="dom-event-defaultprevented" title="dom-Event-defaultPrevented"><code>defaultPrevented</code></dfn>
attribute must return true if the <a href="#canceled-flag">canceled flag</a> is set and
false otherwise.

<hr>

<p>The <dfn id="dom-event-istrusted" title="dom-Event-isTrusted"><code>isTrusted</code></dfn> attribute
must return the value it was initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attribute must be
initialized to false.

<p>The <dfn id="dom-event-timestamp" title="dom-Event-timeStamp"><code>timeStamp</code></dfn> attribute
must return the value it was initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attribute must be
initialized to the number of milliseconds that has passed since
00:00:00 UTC on 1 January 1970.

<!-- XXX leap seconds?
         http://krijnhoetmer.nl/irc-logs/whatwg/20110707#l-330 -->

<hr>

<p>When the <dfn id="dom-event-initevent" title="dom-Event-initEvent"><code>initEvent(<var title="">type</var>, <var title="">bubbles</var>, <var title="">cancelable</var>)</code></dfn>
method is invoked these steps must be run:</p>

<ol>
 <li><p>Set the <a href="#initialized-flag">initialized flag</a>.
 <li><p>If the <a href="#dispatch-flag">dispatch flag</a> is set, terminate these steps.
 <li><p>Unset the <a href="#stop-propagation-flag">stop propagation flag</a>,
 <a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a>, and
 <a href="#canceled-flag">canceled flag</a>.
 <li><p>Set the <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code> attribute
 to false.
 <li><p>Set the <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute to
 null.
 <li><p>Set the <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute to the
 <var title="">type</var> argument.
 <li><p>Set the <code title="dom-Event-bubbles"><a href="#dom-event-bubbles">bubbles</a></code> attribute to
 the <var title="">bubbles</var> argument.
 <li><p>Set the <code title="dom-Event-cancelable"><a href="#dom-event-cancelable">cancelable</a></code> attribute
 to the <var title="">cancelable</var> argument.
</ol>

<p class="note">As <a href="#concept-event" title="concept-event">events</a> have constructors
<code title="dom-Event-initEvent"><a href="#dom-event-initevent">initEvent()</a></code> is superfluous. However,
it has to be supported for legacy content.


<h3 id="interface-customevent"><span class="secno">4.2 </span>Interface <code><a href="#customevent">CustomEvent</a></code></h3>

<pre class="idl">[Constructor(DOMString <var title="">type</var>, optional <a href="#customeventinit">CustomEventInit</a> <var title="">eventInitDict</var>)]
interface <dfn id="customevent">CustomEvent</dfn> : <a href="#event">Event</a> {
  readonly attribute any <a href="#dom-customevent-detail" title="dom-CustomEvent-detail">detail</a>;
};

dictionary <dfn id="customeventinit">CustomEventInit</dfn> : <a href="#eventinit">EventInit</a> {
  any <span title="dom-CustomEventInit-detail">detail</span>;
};</pre>

<p><a href="#concept-event" title="concept-event">Events</a> using the
<code><a href="#customevent">CustomEvent</a></code> interface can be used for synthetic events that
need to carry data.</p>

<p>The <dfn id="dom-customevent-detail" title="dom-CustomEvent-detail"><code>detail</code></dfn> attribute
must return the value it was initialized to. When an
<a href="#concept-event" title="concept-event">event</a> is created the attribute must be
initialized to null.


<h3 id="constructing-events"><span class="secno">4.3 </span>Constructing events</h3>

<p>When a constructor of the <code><a href="#event">Event</a></code> interface, or of an
interface that inherits from the <code><a href="#event">Event</a></code> interface, is invoked,
these steps must be run:

<ol>
 <li><p>Create an <a href="#concept-event" title="concept-event">event</a> that uses the
 interface the constructor was invoked upon.

 <li><p>Set its <a href="#initialized-flag">initialized flag</a>.

 <li><p>Initialize the <code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute to
 the <var title="">type</var> argument.

 <li><p>If there is an <var title="">eventInitDict</var> argument then for each
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a> defined therein find
 the attribute on <a href="#concept-event" title="concept-event">event</a> whose
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-identifier">identifier</a> matches the key of
 the <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a> and then
 set the attribute to the value of that
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-dictionary-member">dictionary member</a>.

 <li><p>Return the <a href="#concept-event" title="concept-event">event</a>.
</ol>


<h3 id="interface-eventtarget"><span class="secno">4.4 </span>Interface <code><a href="#eventtarget">EventTarget</a></code></h3>

<pre class="idl">interface <dfn id="eventtarget">EventTarget</dfn> {
  void <a href="#dom-eventtarget-addeventlistener" title="dom-EventTarget-addEventListener">addEventListener</a>(DOMString <var title="">type</var>, <a href="#eventlistener">EventListener</a>? <var title="">listener</var>, optional boolean <var title="">capture</var>);
  void <a href="#dom-eventtarget-removeeventlistener" title="dom-EventTarget-removeEventListener">removeEventListener</a>(DOMString <var title="">type</var>, <a href="#eventlistener">EventListener</a>? <var title="">listener</var>, optional boolean <var title="">capture</var>);
  boolean <a href="#dom-eventtarget-dispatchevent" title="dom-EventTarget-dispatchEvent">dispatchEvent</a>(<a href="#event">Event</a> <var title="">event</var>);
};

callback interface <dfn id="eventlistener">EventListener</dfn> {
  void <span title="dom-EventListener-handleEvent">handleEvent</span>(<a href="#event">Event</a> <var title="">event</var>);
};</pre>

<p><code><a href="#eventtarget">EventTarget</a></code> is an object upon which an
<a href="#concept-event" title="concept-event">event</a> is
<a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> when something has
occurred. Each <code><a href="#eventtarget">EventTarget</a></code> has an associated list of
<a href="#concept-event-listener" title="concept-event-listener">event listeners</a>.

<p>An <dfn id="concept-event-listener" title="concept-event-listener">event listener</dfn> is a handler
for a specific <a href="#concept-event" title="concept-event">event</a>. Each
<a href="#concept-event-listener" title="concept-event-listener">event listener</a> consists of a
<b>type</b> (of the <a href="#concept-event" title="concept-event">event</a>),
<b>listener</b>, and <b>capture</b> variable.

<p>When the
<dfn id="dom-eventtarget-addeventlistener" title="dom-EventTarget-addEventListener"><code>addEventListener(<var title="">type</var>, <var title="">listener</var>, <var title="">capture</var>)</code></dfn>
method is invoked these steps must be run:
<ol>
 <li><p>If <var title="">listener</var> is null terminate these steps.
 <li><p>If <var title="">capture</var> is omitted let <var title="">capture</var> be false.
 <li><p>Append an <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
 to the associated list of
 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> with <b>type</b>
 set to <var title="">type</var>, <b>listener</b> set to <var title="">listener</var>, and
 <b>capture</b> set to <var title="">capture</var>, unless there
 already is an <a href="#concept-event-listener" title="concept-event-listener">event listener</a> in
 that list with the same <b>type</b>, <b>listener</b>, and <b>capture</b>.
</ol>

<p>When the <dfn id="dom-eventtarget-removeeventlistener" title="dom-EventTarget-removeEventListener"><code>removeEventListener(<var title="">type</var>, <var title="">listener</var>, <var title="">capture</var>)</code></dfn> method is invoked these steps must be run:
<ol>
 <li><p>If <var title="">capture</var> is omitted let <var title="">capture</var> be false.
 <li><p>Remove an <a href="#concept-event-listener" title="concept-event-listener">event listener</a>
 from the associated list of
 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a>, whose
 <b>type</b> is <var title="">name</var>, <b>listener</b> is <var title="">listener</var>, and
 <b>capture</b> is <var title="">capture</var>.</p>
</ol>

<p>When the
<dfn id="dom-eventtarget-dispatchevent" title="dom-EventTarget-dispatchEvent"><code>dispatchEvent(<var title="">event</var>)</code></dfn> method is invoked these steps must be run:
<ol>
 <li><p>If <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a> is set, or if
 its <a href="#initialized-flag">initialized flag</a> is not set,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.
 <li><p>Initialize <var title="">event</var>'s
 <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code> attribute to false.
 <li><p><a href="#concept-event-dispatch" title="concept-event-dispatch">Dispatch</a> the
 <var title="">event</var> and return the value that returns.
</ol>


<h3 id="dispatching-events"><span class="secno">4.5 </span>Dispatching events</h3>

<p>To <dfn id="concept-event-dispatch" title="concept-event-dispatch">dispatch</dfn> an
<a href="#concept-event" title="concept-event">event</a> on a given object run these
steps:</p>
<!-- other specifications turn this into a requirement  -->

<ol>
 <li><p>Let <var title="">event</var> be the
 <a href="#concept-event" title="concept-event">event</a> that is dispatched.
 <li><p>Set <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a>.
 <li><p>Initialize <var title="">event</var>'s
 <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute to the object on which
 <var title="">event</var> is dispatched.
 <li>
  <dl class="switch">
   <dt>If <var title="">event</var>'s
   <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value is
   <a href="#concept-tree-participate" title="concept-tree-participate">participating</a> in a
   <a href="#concept-tree" title="concept-tree">tree</a>
   <dd>
    <ol>
     <li><p>Let <var title="">event path</var> be a static ordered list of all
     <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> of
     <var title="">event</var>'s <code title="dom-Event-target"><a href="#dom-event-target">target</a></code>
     attribute value in <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
     <li><p>Initialize <var title="">event</var>'s
     <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
     <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code>.
     <li><p>For each object in the <var title="">event path</var>
     <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> its
     <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> with event
     <var title="">event</var>, as long as <var title="">event</var>'s
     <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
     <li><p>Initialize <var title="">event</var>'s
     <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
     <code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>.
     <li><p><a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">Invoke</a> the
     <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> of
     <var title="">event</var>'s
     <code title="dom-Event-target"><a href="#dom-event-target">target</a></code> attribute value with
     <var title="">event</var>, if <var title="">event</var>'s
     <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
     <li>
      <p>If <var title="">event</var>'s
      <code title="dom-Event-bubbles"><a href="#dom-event-bubbles">bubbles</a></code> attribute is true run
      these substeps:</p>
      <ol>
       <li><p>Reverse the order of <var title="">event path</var>.
       <li><p>Initialize <var title="">event</var>'s
       <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
       <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code>.
       <li><p>For each object in the <var title="">event path</var>
       <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> its
       <a href="#concept-event-listener" title="concept-event-listener">event listeners</a>, with event
       <var title="">event</var> as long as <var title="">event</var>'s
       <a href="#stop-propagation-flag">stop propagation flag</a> is unset.
      </ol>
    </ol>
   </dd>
   <dt>Otherwise
   <dd><p><a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">Invoke</a> the
   <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> of
   <var title="">event</var>'s <code title="dom-Event-target"><a href="#dom-event-target">target</a></code>
   attribute value, with event <var title="">event</var>.
  </dl>
  <!-- XXX This could be flattened by just letting "event path" be empty for
           objects not participating in a tree. -->
 </li>
 <li><p>Unset <var title="">event</var>'s <a href="#dispatch-flag">dispatch flag</a>.
 <li><p>Initialize <var title="">event</var>'s
 <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute to
 <code title="dom-Event-AT_TARGET"><a href="#dom-event-at_target">AT_TARGET</a></code>.
 <li><p>Initialize <var title="">event</var>'s
 <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> to null.
 <li><p>Return false if <var title="">event</var>'s <a href="#canceled-flag">canceled flag</a>
 is set and true otherwise.
</ol>


<p>To <dfn id="concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</dfn> the
<a href="#concept-event-listener" title="concept-event-listener">event listeners</a> for an object with an
event run these steps:</p>
<ol>
 <li><p>Let <var title="">event</var> be the
 <a href="#concept-event" title="concept-event">event</a> for which the
 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> are invoked.
 <li><p>Let <var title="">listeners</var> be a static list of the
 <a href="#concept-event-listener" title="concept-event-listener">event listeners</a> associated with
 the object for which these steps are run.
 <li><p>Initialize <var title="">event</var>'s
 <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> to the object for
 which these steps are run.
 <li>
  <p>Then run these substeps for each
  <a href="#concept-event-listener" title="concept-event-listener">event listener</a> in
  <var title="">listeners</var>:</p>
  <ol>
   <li><p>If <var title="">event</var>'s
   <a href="#stop-immediate-propagation-flag">stop immediate propagation flag</a> is set, terminate the
   <a href="#concept-event-listener-invoke" title="concept-event-listener-invoke">invoke</a> algorithm.
   <li><p>Let <var title="">listener</var> be the
   <a href="#concept-event-listener" title="concept-event-listener">event listener</a>.
   <li><p>If <var title="">event</var>'s <code title="dom-Event-type"><a href="#dom-event-type">type</a></code>
   attribute value is not <var title="">listener</var>'s <b>type</b>, terminate
   these substeps (and run them for the next
   <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
   <li><p>If <var title="">event</var>'s
   <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute value is
   <code title="dom-Event-CAPTURING_PHASE"><a href="#dom-event-capturing_phase">CAPTURING_PHASE</a></code> and
   <var title="">listener</var>'s <b>capture</b> is false, terminate these
   substeps (and run them for the next
   <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
   <li><p>If <var title="">event</var>'s
   <code title="dom-Event-eventPhase"><a href="#dom-event-eventphase">eventPhase</a></code> attribute value is
   <code title="dom-Event-BUBBLING_PHASE"><a href="#dom-event-bubbling_phase">BUBBLING_PHASE</a></code> and
   <var title="">listener</var>'s <b>capture</b> is true, terminate these
   substeps (and run them for the next
   <a href="#concept-event-listener" title="concept-event-listener">event listener</a>).
   <li><p>If <var title="">listener</var>'s <b>listener</b> is a
   Function<!-- WebIDL uses <span class=estype> --> object, its
   <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-callback-this-value">callback this value</a> is the
   <var title="">event</var>'s
   <code title="dom-Event-currentTarget"><a href="#dom-event-currenttarget">currentTarget</a></code> attribute value.
   <li><p>Call <var title="">listener</var>'s <b>listener</b>, with the event
   passed to this algorithm as the first argument.
  </ol>
 </li>
</ol>


<h3 id="firing-events"><span class="secno">4.6 </span>Firing events</h3>

<p>To
<dfn id="concept-event-fire" title="concept-event-fire">fire an event named <var title="">e</var></dfn>
means that an <a href="#concept-event" title="concept-event">event</a> using the
<code><a href="#event">Event</a></code> interface, with its
<code title="dom-Event-type"><a href="#dom-event-type">type</a></code> attribute initialized to
<var title="">e</var>, and its <code title="dom-Event-isTrusted"><a href="#dom-event-istrusted">isTrusted</a></code>
attribute initialized to true, is to be
<a href="#concept-event-dispatch" title="concept-event-dispatch">dispatched</a> at the given
object.</p>

<p class="note">Fire is short for initializing and
<a href="#concept-event-dispatch" title="concept-event-dispatch">dispatching</a> an
<a href="#concept-event" title="concept-event">event</a>.

<p class="note"><a href="#concept-event-fire" title="concept-event-fire">Fire an event</a> is a
concept to make initializing and
<a href="#concept-event-dispatch" title="concept-event-dispatch">dispatching</a> an
<a href="#concept-event" title="concept-event">event</a> easier to write down. If the
<a href="#concept-event" title="concept-event">event</a> needs its <code>bubbles</code> or
<code>cancelable</code> attribute initialized, one could write
"<a href="#concept-event-fire" title="concept-event-fire">fire an event</a> named
<code title="">submit</code> with its <code>cancelable</code> attribute
initialized to true".



<h2 id="nodes"><span class="secno">5 </span>Nodes</h2>
<h3 id="node-tree"><span class="secno">5.1 </span>Node tree</h3>

<p>Objects implementing the <code><a href="#document">Document</a></code>,
<code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#documenttype">DocumentType</a></code>,
<code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>, <code><a href="#processinginstruction">ProcessingInstruction</a></code>,
or <code><a href="#comment">Comment</a></code> interface (simply called
<dfn id="concept-node" title="concept-node">nodes</dfn>)
<a href="#concept-tree-participate" title="concept-tree-participate">participate</a> in a
<a href="#concept-tree" title="concept-tree">tree</a>.

<p>A <a href="#concept-tree" title="concept-tree">tree</a> of
<a href="#concept-node" title="concept-node">nodes</a> is constrained as follows, expressed
as a relationship between the type of <a href="#concept-node" title="concept-node">node</a>
and its allowed <a href="#concept-tree-child" title="concept-tree-child">children</a>:
<dl>
 <dt><code><a href="#document">Document</a></code>
 <dd>
  <p>In <a href="#concept-tree-order" title="concept-tree-order">tree order</a>:
  <ol>
   <li><p>Zero or more nodes each of which is either
   <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
   <li><p>Optionally one <code><a href="#documenttype">DocumentType</a></code> node.
   <li><p>Zero or more nodes each of which is either
   <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
   <li><p>Optionally one <code><a href="#element">Element</a></code> node.
   <li><p>Zero or more nodes each of which is either
   <code><a href="#processinginstruction">ProcessingInstruction</a></code> or <code><a href="#comment">Comment</a></code>.
  </ol>
 <dt><code><a href="#documentfragment">DocumentFragment</a></code>
 <dt><code><a href="#element">Element</a></code>
 <dd><p>Zero or more nodes each of which is one of <code><a href="#element">Element</a></code>,
 <code><a href="#processinginstruction">ProcessingInstruction</a></code>, <code><a href="#comment">Comment</a></code>, or
 <code><a href="#text">Text</a></code>.
 <dt><code><a href="#documenttype">DocumentType</a></code>
 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dd><p>None.
</dl>

<!--AttrExodus -->

<h4 id="mutation-algorithms"><span class="secno">5.1.1 </span>Mutation algorithms</h4>

<p>To <dfn id="concept-node-pre-insert" title="concept-node-pre-insert">pre-insert</dfn> a
<var title="">node</var> into a <var title="">parent</var> before a
<var title="">child</var>, run these steps:

<ol>
 <li><p>If <var title="">parent</var> is not a <code><a href="#document">Document</a></code>,
 <code><a href="#documentfragment">DocumentFragment</a></code>, or <code><a href="#element">Element</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li><p>If <var title="">node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li><p>If <var title="">child</var> is not null and its
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
 <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.

 <li>
  <p>If <var title="">parent</var> is a
  <a href="#concept-document" title="concept-document">document</a>, run these substeps:

  <ol>
   <li><p>If <var title="">node</var> is not a <code><a href="#documentfragment">DocumentFragment</a></code>,
   <code><a href="#documenttype">DocumentType</a></code>, <code><a href="#element">Element</a></code>,
   <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
   <a href="#concept-node" title="concept-node">node</a>,
   <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

   <li>
    <p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
    <a href="#concept-node" title="concept-node">node</a>, run these inner substeps:

    <ol>
     <li><p>If <var title="">node</var> has more than one
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> or has a <code><a href="#text">Text</a></code>
     <a href="#concept-node" title="concept-node">node</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a>,
     <a href="#concept-throw" title="concept-throw">throw</a> a
     "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

     <li><p>If <var title="">node</var> has one
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> and either
     <var title="">parent</var> has an
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> or <var title="">child</var>
     is not null and a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
     <a href="#concept-tree-following" title="concept-tree-following">following</a>
     <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
     "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
    </ol>

   <li><p>If <var title="">node</var> is an
   <a href="#concept-element" title="concept-element">element</a> and either
   <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
   <a href="#concept-tree-child" title="concept-tree-child">child</a> or <var title="">child</var>
   is not null and a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
   <a href="#concept-tree-following" title="concept-tree-following">following</a>
   <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

   <li><p>If <var title="">node</var> is a
   <a href="#concept-doctype" title="concept-doctype">doctype</a> and either
   <var title="">parent</var> has a <a href="#concept-doctype" title="concept-doctype">doctype</a>
   <a href="#concept-tree-child" title="concept-tree-child">child</a>, an
   <a href="#concept-element" title="concept-element">element</a> is
   <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   <var title="">child</var>, or <var title="">child</var> is null and
   <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
   <a href="#concept-tree-child" title="concept-tree-child">child</a>,
   <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  </ol>

 <li><p>Otherwise if <var title="">parent</var> is a
 <code><a href="#documentfragment">DocumentFragment</a></code> or <code><a href="#element">Element</a></code>
 <a href="#concept-node" title="concept-node">node</a> and <var title="">node</var> is not a
 <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>,
 <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
 <var title="">node</var> with <var title="">parent</var>'s
 <a href="#concept-node-document" title="concept-node-document">node document</a>.

 <li><p><a href="#concept-node-insert" title="concept-node-insert">Insert</a> <var title="">node</var>
 into <var title="">parent</var> before <var title="">child</var>.

 <li><p>Return <var title="">child</var>.
 <!-- technically this is post-insert -->
</ol>


<p>To <dfn id="concept-node-insert" title="concept-node-insert">insert</dfn> a <var title="">node</var>
into a <var title="">parent</var> before a <var title="">child</var>, run these
steps:

<ol>
 <li><p>Let <var title="">count</var> be the number of
 <a href="#concept-tree-child" title="concept-tree-child">children</a> of <var title="">node</var> if
 it is a <code><a href="#documentfragment">DocumentFragment</a></code> <a href="#concept-node" title="concept-node">node</a>,
 or one otherwise.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
 <var title="">parent</var> and
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
 <var title="">child</var>'s <a href="#concept-tree-index" title="concept-tree-index">index</a>,
 increase its <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by
 <var title="">count</var>.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
 <var title="">parent</var> and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
 <var title="">child</var>'s <a href="#concept-tree-index" title="concept-tree-index">index</a>,
 increase its <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by
 <var title="">count</var>.

 <li><p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
 <a href="#concept-node" title="concept-node">node</a>, insert its
 <a href="#concept-tree-child" title="concept-tree-child">children</a> (preserving
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>), before
 <var title="">child</var> or at the end of <var title="">parent</var> if
 <var title="">child</var> is null.

 <li><p>Otherwise insert <var title="">node</var> before
 <var title="">child</var> or at the end of <var title="">parent</var> if
 <var title="">child</var> is null.
</ol>


<p>To <dfn id="concept-node-append" title="concept-node-append">append</dfn> a <var title="">node</var>
to a <var title="">parent</var>,
<a href="#concept-node-pre-insert" title="concept-node-pre-insert">pre-insert</a> <var title="">node</var>
into <var title="">parent</var> before null.


<p>To <dfn id="concept-node-replace" title="concept-node-replace">replace</dfn> a <var title="">child</var>
with <var title="">node</var> within a <var title="">parent</var>, run these
steps:

<ol>
 <li><p>If <var title="">child</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
 <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li><p>If <var title="">parent</var> is not a <code><a href="#document">Document</a></code>,
 <code><a href="#documentfragment">DocumentFragment</a></code>, or <code><a href="#element">Element</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li>
  <p>If <var title="">parent</var> is a
  <a href="#concept-document" title="concept-document">document</a>, run these substeps:

  <ol>
   <li><p>If <var title="">node</var> is not a <code><a href="#documentfragment">DocumentFragment</a></code>,
   <code><a href="#documenttype">DocumentType</a></code>, <code><a href="#element">Element</a></code>,
   <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
   <a href="#concept-node" title="concept-node">node</a>,
   <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

   <li>
    <p>If <var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
    <a href="#concept-node" title="concept-node">node</a>, run these inner substeps:

    <ol>
     <li><p>If <var title="">node</var> has more than one
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> or has a <code><a href="#text">Text</a></code>
     <a href="#concept-node" title="concept-node">node</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a>,
     <a href="#concept-throw" title="concept-throw">throw</a> a
     "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

     <li><p>If <var title="">node</var> has one
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> and either
     <var title="">parent</var> has an
     <a href="#concept-element" title="concept-element">element</a>
     <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
     <var title="">child</var> or a <a href="#concept-doctype" title="concept-doctype">doctype</a>
     is <a href="#concept-tree-following" title="concept-tree-following">following</a>
     <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
     "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
    </ol>

   <li><p>If <var title="">node</var> is an
   <a href="#concept-element" title="concept-element">element</a> and either
   <var title="">parent</var> has an <a href="#concept-element" title="concept-element">element</a>
   <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
   <var title="">child</var> or a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
   <a href="#concept-tree-following" title="concept-tree-following">following</a>
   <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

   <li><p>If <var title="">node</var> is a
   <a href="#concept-doctype" title="concept-doctype">doctype</a> and either
   <var title="">parent</var> has a <a href="#concept-doctype" title="concept-doctype">doctype</a>
   <a href="#concept-tree-child" title="concept-tree-child">child</a> that is not
   <var title="">child</var>, or an <a href="#concept-element" title="concept-element">element</a>
   is <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   <var title="">child</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
   "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.
  </ol>

 <li><p>Otherwise if <var title="">parent</var> is a
 <code><a href="#documentfragment">DocumentFragment</a></code> or <code><a href="#element">Element</a></code>
 <a href="#concept-node" title="concept-node">node</a> and <var title="">node</var> is not a
 <code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>,
 <code><a href="#processinginstruction">ProcessingInstruction</a></code>, or <code><a href="#comment">Comment</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" and terminate these steps.

 <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
 <var title="">node</var> with <var title="">parent</var>'s
 <a href="#concept-node-document" title="concept-node-document">node document</a>.

 <li><p>Let <var title="">reference child</var> be <var title="">child</var>'s
 <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.

 <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> <var title="">child</var>
 from its <var title="">parent</var>.

 <li><p><a href="#concept-node-insert" title="concept-node-insert">Insert</a> <var title="">node</var>
 into <var title="">parent</var> before <var title="">reference child</var>.

 <li><p>Return <var title="">child</var>.
</ol>


<p>To <dfn id="concept-node-replace-all" title="concept-node-replace-all">replace all</dfn> with a
<var title="">node</var> within a <var title="">parent</var>, run these steps:

<ol>
 <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a>
 <var title="">node</var> with <var title="">parent</var>'s
 <a href="#concept-node-document" title="concept-node-document">node document</a>.

 <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> all
 <var title="">parent</var>'s <a href="#concept-tree-child" title="concept-tree-child">children</a>,
 in <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <li><p>If <var title="">node</var> is not null,
 <a href="#concept-node-append" title="concept-node-append">append</a> <var title="">node</var> to
 <var title="">parent</var>.
</ol>

<p class="note">This algorithm does not make any checks with regards to the
<a href="#node-tree">node tree</a>. Use it wisely.


<p>To <dfn id="concept-node-pre-remove" title="concept-node-pre-remove">pre-remove</dfn> a
<var title="">node</var> from a <var title="">parent</var>, run these steps:</p>

<ol>
 <li><p>If <var title="">child</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not
 <var title="">parent</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notfounderror">NotFoundError</a></code>" exception and terminate these steps.

 <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> <var title="">child</var>
 from <var title="">parent</var>.

 <li><p>Return <var title="">child</var>.
 <!-- technically this is post-remove -->
</ol>


<p>To <dfn id="concept-node-remove" title="concept-node-remove">remove</dfn> a <var title="">node</var>
from a <var title="">parent</var>, run these steps:

<ol>
 <li><p>Let <var title="">index</var> be <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a>.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is a
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
 <var title="">parent</var>, set its
 <a href="#concept-range-start" title="concept-range-start">start</a> to
 (<var title="">parent</var>, <var title="">index</var>).

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is a
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
 <var title="">parent</var>, set its
 <a href="#concept-range-end" title="concept-range-end">end</a> to
 (<var title="">parent</var>, <var title="">index</var>).

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
 <var title="">parent</var> and
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
 <var title="">index</var>, decrease its
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by one.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
 <var title="">parent</var> and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
 <var title="">index</var>, decrease its
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by one.

 <li><p>Remove <var title="">node</var> from its <var title="">parent</var>.
</ol>


<h4 id="mutation-methods"><span class="secno">5.1.2 </span>Mutation methods</h4>

<p>The <dfn id="mutation-method-macro">mutation method macro</dfn>:

<ol>
 <li><p>Let <var title="">node</var> be null.

 <li><p>Replace each string in <var title="">nodes</var> with a
 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> whose
 <span title="cocnept-CD-data">data</span> is the string value.

 <li>
  <p>If <var title="">nodes</var> contains more than one
  <a href="#concept-node" title="concept-node">node</a>, set <var title="">node</var> to a new
  <code><a href="#documentfragment">DocumentFragment</a></code> and
  <a href="#concept-node-append" title="concept-node-append">append</a> each
  <a href="#concept-node" title="concept-node">node</a> in <var title="">nodes</var> to it. If
  this throws an exception, re-throw the exception and terminate these
  steps.

  <p>Otherwise, set <var title="">node</var> to the single
  <a href="#concept-node" title="concept-node">node</a> <var title="">nodes</var> contains.
</ol>


<p>The
<dfn id="dom-rootnode-prepend" title="dom-RootNode-prepend"><code>prepend(<var>nodes</var>)</code></dfn>
method must run these steps:

<ol>
 <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.

 <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
 <var title="">node</var> into the <a href="#context-object">context object</a> before the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.
</ol>

<p>The
<dfn id="dom-rootnode-append" title="dom-RootNode-append"><code>append(<var>nodes</var>)</code></dfn>
method must run these steps:

<ol>
 <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.

 <li><p><a href="#concept-node-append" title="concept-node-append">Append</a>
 <var title="">node</var> to the <a href="#context-object">context object</a>.
</ol>


<p>The
<dfn id="dom-childnode-before" title="dom-ChildNode-before"><code>before(<var>nodes</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#context-object">context object</a> does not have a
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.

 <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.

 <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
 <var title="">node</var> into the <a href="#context-object">context object</a>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> before the
 <a href="#context-object">context object</a>.
</ol>

<p>The
<dfn id="dom-childnode-after" title="dom-ChildNode-after"><code>after(<var>nodes</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#context-object">context object</a> does not have a
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.

 <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.

 <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
 <var title="">node</var> into the <a href="#context-object">context object</a>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> before the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
</ol>

<p>The
<dfn id="dom-childnode-replace" title="dom-ChildNode-replace"><code>replace(<var>nodes</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#context-object">context object</a> does not have a
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.

 <li>Run the <a href="#mutation-method-macro">mutation method macro</a>.

 <li><p><a href="#concept-node-replace" title="concept-node-replace">Replace</a> the
 <a href="#context-object">context object</a> with <var title="">node</var> within the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
</ol>

<p>The
<dfn id="dom-childnode-remove" title="dom-ChildNode-remove"><code>remove()</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#context-object">context object</a> does not have a
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, terminate these steps.

 <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a> the
 <a href="#context-object">context object</a> from the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
</ol>


<h4 id="legacy-mutation-methods"><span class="secno">5.1.3 </span>Legacy mutation methods</h4>

<p>The
<dfn id="dom-node-insertbefore" title="dom-Node-insertBefore"><code>insertBefore(<var>node</var>, <var>child</var>)</code></dfn>
method must return the result of
<a href="#concept-node-pre-insert" title="concept-node-pre-insert">pre-inserting</a>
<var title="">node</var> into the <a href="#context-object">context object</a> before
<var title="">child</var>.

<p>The
<dfn id="dom-node-appendchild" title="dom-Node-appendChild"><code>appendChild(<var>node</var>)</code></dfn>
method must return the result of
<a href="#concept-node-append" title="concept-node-append">appending</a> <var title="">node</var> to
the <a href="#context-object">context object</a>.

<p>The
<dfn id="dom-node-replacechild" title="dom-Node-replaceChild"><code>replaceChild(<var>node</var>, <var>child</var>)</code></dfn>
method must return the result of
<a href="#concept-node-replace" title="concept-node-replace">replacing</a> <var title="">child</var>
with <var title="">node</var> within the <a href="#context-object">context object</a>.

<p>The
<dfn id="dom-node-removechild" title="dom-Node-removeChild"><code>removeChild(<var>child</var>)</code></dfn>
method must return the result of
<a href="#concept-node-pre-remove" title="concept-node-pre-remove">pre-removing</a>
<var title="">child</var> from the <a href="#context-object">context object</a>.


<h4 id="mutation-observers"><span class="secno">5.1.4 </span>Mutation observers</h4>

<p class="XXX">This section will define the replacement for the
"Mutation Events" feature of the platform. For now it contains the interface
being implemented by vendors.

<pre class="idl">[Constructor(<a href="#mutationcallback">MutationCallback</a> callback)]
interface <dfn id="mutationobserver">MutationObserver</dfn> {
  void observe(<a href="#node">Node</a> target, <a href="#mutationobserverinit">MutationObserverInit</a> options);
  void disconnect();
};

callback <dfn id="mutationcallback">MutationCallback</dfn> = void (<a href="#mutationrecord">MutationRecord</a>[] mutations, <a href="#mutationobserver">MutationObserver</a> observer);

dictionary <dfn id="mutationobserverinit">MutationObserverInit</dfn> {
  // Mutation types
  boolean childList;     // If true, mutations affecting node&rsquo;s childNodes are included.
  boolean attributes;    // If true, mutations affecting element&rsquo;s attributes are included.
  boolean characterData; // If true, mutations affecting the value of CharacterData nodes are included.
  // [Note: If none of the known mutation types is specified, an Error is thrown]

  // Subtree observation
  boolean subtree;  // If true, the observed set of nodes for this registration should include
                    // descendants of MutationTarget (behavior described below).

  // Old values
  boolean attributeOldValue;
  // If true, MutationRecords describing changes to attributes should
  // contain the value of the attribute before the change. If true
  // without attribute: true specified, an Error is thrown.

  boolean characterDataOldValue;
  // If true, MutationRecords describing changes to
  // CharacterData nodes should contain the value
  // of the node before the change. If true without
  // characterData: true, an Error is thrown.

  // Filtering
  DOMString[] attributeFilter;
  // If provided, only changes to attributes with localName equaling
  // one of the provided strings will be delivered. If provided without
  // attribute: true, an Error is thrown.
};

interface <dfn id="mutationrecord">MutationRecord</dfn> {
  // Mutation type: one of 'childList', 'attributes', or 'characterData'
  readonly attribute DOMString type;

  // For childList and attributes, target is the owner node affected.
  // For CharacterData, target is the node affected.
  readonly attribute <a href="#node">Node</a> target;

  // For type == 'childList', Sequence of added and removed nodes in this operation.
  readonly attribute <a href="#nodelist">NodeList</a> addedNodes;
  readonly attribute <a href="#nodelist">NodeList</a> removedNodes;

  // For type == 'childList', The siblings in childNodes immediately preceding following the first
  // and last nodes added and/or removed.
  readonly attribute <a href="#node">Node</a> previousSibling;
  readonly attribute <a href="#node">Node</a> nextSibling;

  // For type == 'attribute', the name and namespaceURI of the attribute affected
  readonly attribute DOMString attributeName;
  readonly attribute DOMString attributeNamespace;

  // For type == 'attribute' or 'characterData', if requested, the value immediately
  // preceding the mutation.
  readonly attribute DOMString oldValue;
};</pre>
<!-- XXX remove inline comments when this is defined -->


<h3 id="interface-node"><span class="secno">5.2 </span>Interface <code><a href="#node">Node</a></code></h3>
<pre class="idl">interface <dfn id="node">Node</dfn> : <a href="#eventtarget">EventTarget</a> {
  const unsigned short <a href="#dom-node-element_node" title="dom-Node-ELEMENT_NODE">ELEMENT_NODE</a> = 1;
  const unsigned short <span title="dom-Node-ATTRIBUTE_NODE">ATTRIBUTE_NODE</span> = 2; // historical
  const unsigned short <a href="#dom-node-text_node" title="dom-Node-TEXT_NODE">TEXT_NODE</a> = 3;
  const unsigned short <span title="dom-Node-CDATA_SECTION_NODE">CDATA_SECTION_NODE</span> = 4; // historical
  const unsigned short <span title="dom-Node-ENTITY_REFERENCE_NODE">ENTITY_REFERENCE_NODE</span> = 5; // historical
  const unsigned short <span title="dom-Node-ENTITY_NODE">ENTITY_NODE</span> = 6; // historical
  const unsigned short <a href="#dom-node-processing_instruction_node" title="dom-Node-PROCESSING_INSTRUCTION_NODE">PROCESSING_INSTRUCTION_NODE</a> = 7;
  const unsigned short <a href="#dom-node-comment_node" title="dom-Node-COMMENT_NODE">COMMENT_NODE</a> = 8;
  const unsigned short <a href="#dom-node-document_node" title="dom-Node-DOCUMENT_NODE">DOCUMENT_NODE</a> = 9;
  const unsigned short <a href="#dom-node-document_type_node" title="dom-Node-DOCUMENT_TYPE_NODE">DOCUMENT_TYPE_NODE</a> = 10;
  const unsigned short <a href="#dom-node-document_fragment_node" title="dom-Node-DOCUMENT_FRAGMENT_NODE">DOCUMENT_FRAGMENT_NODE</a> = 11;
  const unsigned short <span title="dom-Node-NOTATION_NODE">NOTATION_NODE</span> = 12; // historical
  readonly attribute unsigned short <a href="#dom-node-nodetype" title="dom-Node-nodeType">nodeType</a>;<!-- NodeExodus

  readonly attribute DOMString <span title=dom-Node-namespaceURI>namespaceURI</span>;
  readonly attribute DOMString <span title=dom-Node-prefix>prefix</span>;
  readonly attribute DOMString <span title=dom-Node-localName>localName</span>;-->
  readonly attribute DOMString <a href="#dom-node-nodename" title="dom-Node-nodeName">nodeName</a>;

  readonly attribute DOMString? <a href="#dom-node-baseuri" title="dom-Node-baseURI">baseURI</a>;

  <!--AttrExodus
  boolean <span title=dom-Node-hasAttributes>hasAttributes</span>();
  readonly attribute <span>NamedNodeMap</span> <span title=dom-Node-attributes>attributes</span>;

  -->readonly attribute <a href="#document">Document</a>? <a href="#dom-node-ownerdocument" title="dom-Node-ownerDocument">ownerDocument</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-node-parentnode" title="dom-Node-parentNode">parentNode</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-node-parentelement" title="dom-Node-parentElement">parentElement</a>;
  boolean <a href="#dom-node-haschildnodes" title="dom-Node-hasChildNodes">hasChildNodes</a>();
  readonly attribute <a href="#nodelist">NodeList</a> <a href="#dom-node-childnodes" title="dom-Node-childNodes">childNodes</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-node-firstchild" title="dom-Node-firstChild">firstChild</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-node-lastchild" title="dom-Node-lastChild">lastChild</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-node-previoussibling" title="dom-Node-previousSibling">previousSibling</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-node-nextsibling" title="dom-Node-nextSibling">nextSibling</a>;

  const unsigned short <a href="#dom-node-document_position_disconnected" title="dom-Node-DOCUMENT_POSITION_DISCONNECTED">DOCUMENT_POSITION_DISCONNECTED</a> = 0x01;
  const unsigned short <a href="#dom-node-document_position_preceding" title="dom-Node-DOCUMENT_POSITION_PRECEDING">DOCUMENT_POSITION_PRECEDING</a> = 0x02;
  const unsigned short <a href="#dom-node-document_position_following" title="dom-Node-DOCUMENT_POSITION_FOLLOWING">DOCUMENT_POSITION_FOLLOWING</a> = 0x04;
  const unsigned short <a href="#dom-node-document_position_contains" title="dom-Node-DOCUMENT_POSITION_CONTAINS">DOCUMENT_POSITION_CONTAINS</a> = 0x08;
  const unsigned short <a href="#dom-node-document_position_contained_by" title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY">DOCUMENT_POSITION_CONTAINED_BY</a> = 0x10;
  const unsigned short <span title="dom-Node-DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC">DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC</span> = 0x20; // historical
  unsigned short <a href="#dom-node-comparedocumentposition" title="dom-Node-compareDocumentPosition">compareDocumentPosition</a>(<a href="#node">Node</a> <var title="">other</var>);
  boolean <a href="#dom-node-contains" title="dom-Node-contains">contains</a>(<a href="#node">Node</a>? <var title="">other</var>);

           attribute DOMString? <a href="#dom-node-nodevalue" title="dom-Node-nodeValue">nodeValue</a>;
           attribute DOMString? <a href="#dom-node-textcontent" title="dom-Node-textContent">textContent</a>;
  <a href="#node">Node</a> <a href="#dom-node-insertbefore" title="dom-Node-insertBefore">insertBefore</a>(<a href="#node">Node</a> <var title="">node</var>, <a href="#node">Node</a>? <var title="">child</var>);
  <a href="#node">Node</a> <a href="#dom-node-appendchild" title="dom-Node-appendChild">appendChild</a>(<a href="#node">Node</a> <var title="">node</var>);
  <a href="#node">Node</a> <a href="#dom-node-replacechild" title="dom-Node-replaceChild">replaceChild</a>(<a href="#node">Node</a> <var title="">node</var>, <a href="#node">Node</a> <var title="">child</var>);
  <a href="#node">Node</a> <a href="#dom-node-removechild" title="dom-Node-removeChild">removeChild</a>(<a href="#node">Node</a> <var title="">child</var>);
  void <a href="#dom-node-normalize" title="dom-Node-normalize">normalize</a>();

  <a href="#node">Node</a> <a href="#dom-node-clonenode" title="dom-Node-cloneNode">cloneNode</a>(optional boolean <var title="">deep</var>);
  boolean <a href="#dom-node-isequalnode" title="dom-Node-isEqualNode">isEqualNode</a>(<a href="#node">Node</a>? <var title="">node</var>);

  DOMString <a href="#dom-node-lookupprefix" title="dom-Node-lookupPrefix">lookupPrefix</a>(DOMString? <var title="">namespace</var>);
  DOMString <a href="#dom-node-lookupnamespaceuri" title="dom-Node-lookupNamespaceURI">lookupNamespaceURI</a>(DOMString? <var title="">prefix</var>);
  boolean <a href="#dom-node-isdefaultnamespace" title="dom-Node-isDefaultNamespace">isDefaultNamespace</a>(DOMString? <var title="">namespace</var>);
};</pre>

<p class="note"><code><a href="#node">Node</a></code> is an abstract interface and does not exist
as <a href="#concept-node" title="concept-node">node</a>. It is used by all
<a href="#concept-node" title="concept-node">nodes</a> (<code><a href="#document">Document</a></code>,
<code><a href="#documentfragment">DocumentFragment</a></code>, <code><a href="#documenttype">DocumentType</a></code>,
<code><a href="#element">Element</a></code>, <code><a href="#text">Text</a></code>, <code><a href="#processinginstruction">ProcessingInstruction</a></code>,
and <code><a href="#comment">Comment</a></code>).

<p>Each <a href="#concept-node" title="concept-node">node</a> has an associated
<dfn id="concept-node-document" title="concept-node-document">node document</dfn>, set upon creation,
that is a <a href="#concept-document" title="concept-document">document</a>.

<p class="note">A <a href="#concept-node" title="concept-node">node</a>'s
<a href="#concept-node-document" title="concept-node-document">node document</a> can be changed by
the "<a href="#concept-node-adopt" title="concept-node-adopt">adopt</a>" algorithm.

<p>Each <a href="#concept-node" title="concept-node">node</a> also has an associated
<dfn id="concept-node-base-url" title="concept-node-base-url">base URL</dfn>.

<p class="note">Other specifications define the value of the
<a href="#concept-node-base-url" title="concept-node-base-url">base URL</a> and its observable
behavior. This specification solely defines the concept and the
<code title="dom-Node-baseURI"><a href="#dom-node-baseuri">baseURI</a></code> attribute.

<hr>

<dl class="domintro">
 <dt><var title="">node</var> . <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code></dt>
 <dd>
  <p>Returns the type of <var title="">node</var>, represented by a number from the following list:</p>

  <dl>
   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-ELEMENT_NODE"><a href="#dom-node-element_node">ELEMENT_NODE</a></code> (1)
   <dd><var title="">node</var> is an
   <a href="#concept-element" title="concept-element">element</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-TEXT_NODE"><a href="#dom-node-text_node">TEXT_NODE</a></code> (3)
   <dd><var title="">node</var> is a <code><a href="#text">Text</a></code>
   <a href="#concept-node" title="concept-node">node</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-PROCESSING_INSTRUCTION_NODE"><a href="#dom-node-processing_instruction_node">PROCESSING_INSTRUCTION_NODE</a></code> (7)
   <dd><var title="">node</var> is a <code><a href="#processinginstruction">ProcessingInstruction</a></code>
   <a href="#concept-node" title="concept-node">node</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-COMMENT_NODE"><a href="#dom-node-comment_node">COMMENT_NODE</a></code> (8)
   <dd><var title="">node</var> is a <code><a href="#comment">Comment</a></code>
   <a href="#concept-node" title="concept-node">node</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-DOCUMENT_NODE"><a href="#dom-node-document_node">DOCUMENT_NODE</a></code> (9)
   <dd><var title="">node</var> is a
   <a href="#concept-document" title="concept-document">document</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-DOCUMENT_TYPE_NODE"><a href="#dom-node-document_type_node">DOCUMENT_TYPE_NODE</a></code> (10)
   <dd><var title="">node</var> is a
   <a href="#concept-doctype" title="concept-doctype">doctype</a>.

   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-DOCUMENT_FRAGMENT_NODE"><a href="#dom-node-document_fragment_node">DOCUMENT_FRAGMENT_NODE</a></code> (11)
   <dd><var title="">node</var> is a <code><a href="#documentfragment">DocumentFragment</a></code>
   <a href="#concept-node" title="concept-node">node</a>.
  </dl>

 <dt><var title="">node</var> . <code title="dom-Node-nodeName"><a href="#dom-node-nodename">nodeName</a></code>
 <dd>
  <p>Returns a string appropriate for the type of <var title="">node</var>, as
  follows:

  <dl>
   <dt><code><a href="#element">Element</a></code>
   <dd>Its <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code> attribute value.

   <dt><code><a href="#text">Text</a></code>
   <dd>"<code title="">#text</code>".

   <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
   <dd>Its <a href="#concept-pi-target" title="concept-PI-target">target</a>.

   <dt><code><a href="#comment">Comment</a></code>
   <dd>"<code title="">#comment</code>".

   <dt><code><a href="#document">Document</a></code>
   <dd>"<code title="">#document</code>".

   <dt><code><a href="#documenttype">DocumentType</a></code>
   <dd>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.

   <dt><code><a href="#documentfragment">DocumentFragment</a></code>
   <dd>"<code title="">#document-fragment</code>".
  </dl>
</dl>

<p>The <dfn id="dom-node-nodetype" title="dom-Node-nodeType"><code>nodeType</code></dfn> attribute
must return the type of the node, which must be one of the following:

<ul>
 <li><dfn id="dom-node-element_node" title="dom-Node-ELEMENT_NODE"><code>ELEMENT_NODE</code></dfn> (1);

 <!--AttrExodus
 <li><dfn title=dom-Node-ATTRIBUTE_NODE><code>ATTRIBUTE_NODE</code></dfn> (2, historical);
 -->

 <li><dfn id="dom-node-text_node" title="dom-Node-TEXT_NODE"><code>TEXT_NODE</code></dfn> (3);

 <!-- XXX still questionable
 <li><dfn title=dom-Node-CDATA_SECTION_NODE><code>CDATA_SECTION_NODE</code></dfn> (4, historical);
 -->

 <li><dfn id="dom-node-processing_instruction_node" title="dom-Node-PROCESSING_INSTRUCTION_NODE"><code>PROCESSING_INSTRUCTION_NODE</code></dfn> (7);

 <li><dfn id="dom-node-comment_node" title="dom-Node-COMMENT_NODE"><code>COMMENT_NODE</code></dfn> (8);

 <li><dfn id="dom-node-document_node" title="dom-Node-DOCUMENT_NODE"><code>DOCUMENT_NODE</code></dfn> (9);

 <li><dfn id="dom-node-document_type_node" title="dom-Node-DOCUMENT_TYPE_NODE"><code>DOCUMENT_TYPE_NODE</code></dfn> (10);

 <li><dfn id="dom-node-document_fragment_node" title="dom-Node-DOCUMENT_FRAGMENT_NODE"><code>DOCUMENT_FRAGMENT_NODE</code></dfn> (11).
</ul>


<!-- NodeExodus
<hr>

<p>The <dfn title=dom-Node-namespaceURI><code>namespaceURI</code></dfn> attribute must return the namespace that is associated with the node, if there is one and it's not the empty string, or null otherwise.

<p>The <dfn title=dom-Node-prefix><code>prefix</code></dfn> attribute must return the prefix that is associated with the node, if there is one and it's not the empty string, or null otherwise.
<!- - support setting? - - On setting, it must run these steps:

<ol>
 <li><p>Let <var title>prefix</var> be the value being assigned.
 <li>
  <p>If <var title>prefix</var> is not null, run these substeps:
  <ol>
   <li><p>If <var title>prefix</var> does not match the
   <code data-anolis-spec=xml>Name</code> production in XML,
   <span title=concept-throw>throw</span> an
   "<code>InvalidCharacterError</code>" exception and terminate these
   steps.
   <li><p>If <var title>prefix</var> does not match the <code
   data-anolis-spec=xmlns>NCName</code> production in Namespaces in XML, <span title=concept-throw>throw</span> a
   "<code>NamespaceError</code>" exception and
   terminate these steps.
  </ol>
 <li><p>Actually this does not match any browser. Let's try to drop it instead.
</ol>- ->

<p>The <dfn title=dom-Node-localName><code>localName</code></dfn> attribute
must return the local name that is associated with the node, if it has one,
and null otherwise.-->

<p>The <dfn id="dom-node-nodename" title="dom-Node-nodeName"><code>nodeName</code></dfn> attribute
must return the following, depending on the <a href="#context-object">context object</a>:

<dl class="switch">
 <dt><code><a href="#element">Element</a></code>
 <dd><p>Its <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code> attribute value.

 <!--AttrExodus
 <dt><code>Attr</code>
 <dd><p>The <span>context object</span>'s
 <code title=dom-Attr-name>name</code> attribute.
 -->

 <dt><code><a href="#text">Text</a></code>
 <dd><p>"<code title="">#text</code>".

 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a>.

 <dt><code><a href="#comment">Comment</a></code>
 <dd><p>"<code title="">#comment</code>".

 <dt><code><a href="#document">Document</a></code>
 <dd><p>"<code title="">#document</code>".

 <dt><code><a href="#documenttype">DocumentType</a></code>
 <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.

 <dt><code><a href="#documentfragment">DocumentFragment</a></code>
 <dd><p>"<code title="">#document-fragment</code>".
</dl>

<hr>

<dl class="domintro">
 <dt><var title="">node</var> . <code title="dom-Node-baseURI"><a href="#dom-node-baseuri">baseURI</a></code>
 <dd><p>Returns the <a href="#concept-node-base-url" title="concept-node-base-url">base URL</a>.
</dl>

<p>The <dfn id="dom-node-baseuri" title="dom-Node-baseURI"><code>baseURI</code></dfn> attribute must return the associated <a href="#concept-node-base-url" title="concept-node-base-url">base URL</a>.

<!--AttrExodus
<hr>

<p>The <dfn title=dom-Node-hasAttributes><code>hasAttributes()</code></dfn>
method must return true if there are any attributes associated with the
<span>context object</span>, if it is an <code>Element</code> node, and false
otherwise.

<p>The <dfn title=dom-Node-attributes><code>attributes</code></dfn> attribute must return a <code>NamedNodeMap</code> of all the <code>Attr</code> nodes associated with the node of the <span>context object</span>, if it is an <code>Element</code> node, or null otherwise.
-->

<hr>

<dl class="domintro">
 <dt><var title="">doc</var> = <var title="">node</var> .
 <code title="dom-Node-ownerDocument"><a href="#dom-node-ownerdocument">ownerDocument</a></code>
 <dd>
  <p>Returns the <a href="#concept-node-document" title="concept-node-document">node document</a>.
  <p>Returns null for <a href="#concept-document" title="concept-document">documents</a>.

 <dt><var title="">parent</var> = <var title="">node</var> .
 <code title="dom-Node-parentNode"><a href="#dom-node-parentnode">parentNode</a></code>
 <dd><p>Returns the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <dt><var title="">parent</var> = <var title="">node</var> .
 <code title="dom-Node-parentElement"><a href="#dom-node-parentelement">parentElement</a></code>
 <dd><p>Returns the <a href="#parent-element">parent element</a>.

 <dt><var title="">haschildren</var> = <var title="">node</var> .
 <code title="dom-Node-hasChildNodes"><a href="#dom-node-haschildnodes">hasChildNodes</a></code>
 <dd><p>Returns whether <var title="">node</var> has
 <a href="#concept-tree-child" title="concept-tree-child">children</a>.

 <dt><var title="">children</var> = <var title="">node</var> .
 <code title="dom-Node-childNodes"><a href="#dom-node-childnodes">childNodes</a></code>
 <dd><p>Returns the <a href="#concept-tree-child" title="concept-tree-child">children</a>.

 <dt><var title="">child</var> = <var title="">node</var> .
 <code title="dom-Node-firstChild"><a href="#dom-node-firstchild">firstChild</a></code>
 <dd><p>Returns the <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.

 <dt><var title="">child</var> = <var title="">node</var> .
 <code title="dom-Node-lastChild"><a href="#dom-node-lastchild">lastChild</a></code>
 <dd><p>Returns the <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>.

 <dt><var title="">child</var> = <var title="">node</var> .
 <code title="dom-Node-previousSibling"><a href="#dom-node-previoussibling">previousSibling</a></code>
 <dd><p>Returns the
 <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.

 <dt><var title="">child</var> = <var title="">node</var> .
 <code title="dom-Node-nextSibling"><a href="#dom-node-nextsibling">nextSibling</a></code>
 <dd><p>Returns the
 <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
</dl>

<div class="impl">

<p>The <dfn id="dom-node-ownerdocument" title="dom-Node-ownerDocument"><code>ownerDocument</code></dfn>
attribute must run these steps:
<ol>
 <li>If the <a href="#context-object">context object</a> is a
 <a href="#concept-document" title="concept-document">document</a>, return null and terminate these
 steps.

 <li>Return the <a href="#concept-node-document" title="concept-node-document">node document</a>.
</ol>

<div class="note">
<p>The <a href="#concept-node-document" title="concept-node-document">node document</a> of a
<a href="#concept-document" title="concept-document">document</a> is that
<a href="#concept-document" title="concept-document">document</a> itself.
<p>All <a href="#concept-node" title="concept-node">nodes</a> have a
<a href="#concept-document" title="concept-document">document</a> at all times.
</div>

<p>The <dfn id="dom-node-parentnode" title="dom-Node-parentNode"><code>parentNode</code></dfn>
attribute must return the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
<!-- AttrExodus
<li><p>If the <span>context object</span> is an <code>Attr</code> node,
return null and terminate these steps.
-->

<p>The <dfn id="dom-node-parentelement" title="dom-Node-parentElement"><code>parentElement</code></dfn>
attribute must return the <a href="#parent-element">parent element</a>.

<p>The <dfn id="dom-node-haschildnodes" title="dom-Node-hasChildNodes"><code>hasChildNodes()</code></dfn>
method must return true if the <a href="#context-object">context object</a> has
<a href="#concept-tree-child" title="concept-tree-child">children</a>, or false otherwise.

<p>The <dfn id="dom-node-childnodes" title="dom-Node-childNodes"><code>childNodes</code></dfn>
attribute must return a <code><a href="#nodelist">NodeList</a></code> rooted at the
<a href="#context-object">context object</a> matching only
<a href="#concept-tree-child" title="concept-tree-child">children</a>.

<p>The <dfn id="dom-node-firstchild" title="dom-Node-firstChild"><code>firstChild</code></dfn>
attribute must return the
<a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>.

<p>The <dfn id="dom-node-lastchild" title="dom-Node-lastChild"><code>lastChild</code></dfn> attribute must return the <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>.

<p>The
<dfn id="dom-node-previoussibling" title="dom-Node-previousSibling"><code>previousSibling</code></dfn>
attribute must return the
<a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>.
<!-- AttrExodus
 <li><p>If the <span>context object</span> is an <code>Attr</code> node,
 return null and terminate these steps.
-->

<p>The <dfn id="dom-node-nextsibling" title="dom-Node-nextSibling"><code>nextSibling</code></dfn>
attribute must return the
<a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
<!-- AttrExodus
 <li><p>If the <span>context object</span> is an <code>Attr</code> node,
 return null and terminate these steps.
-->

</div>

<hr>

<dl class="domintro">
 <dt><var title="">node</var> . <code title="dom-Node-compareDocumentPosition"><a href="#dom-node-comparedocumentposition">compareDocumentPosition(<var title="">other</var>)</a></code>
 <dd>
  <p>Returns a bitmask indicating the position of <var title="">other</var>
  relative to <var title="">node</var>. These are the bits that can be set:

  <dl>
   <dt><code><a href="#node">Node</a></code> . <code title="dom-Node-DOCUMENT_POSITION_DISCONNECTED"><a href="#dom-node-document_position_disconnected">DOCUMENT_POSITION_DISCONNECTED</a></code> (1)
   <dd>Set when <var title="">node</var> and <var>other</var> are not in the
   same <a href="#concept-document" title="concept-document">document</a>.

   <dt><code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code> (2)
   <dd>Set when <var title="">other</var> is
   <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
   <var title="">node</var>.

   <dt><code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code> (4)
   <dd>Set when <var title="">other</var> is
   <a href="#concept-tree-following" title="concept-tree-following">following</a>
   <var title="">node</var>.

   <dt><code title="dom-Node-DOCUMENT_POSITION_CONTAINS"><a href="#dom-node-document_position_contains">DOCUMENT_POSITION_CONTAINS</a></code> (8)
   <dd>Set when <var title="">other</var> is an
   <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of
   <var title="">node</var>.

   <dt><code title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY"><a href="#dom-node-document_position_contained_by">DOCUMENT_POSITION_CONTAINED_BY</a></code> (16, 10 in hexadecimal)
   <dd>Set when <var title="">other</var> is a
   <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
   <var title="">node</var>.
  </dl>

 <dt><var title="">contains</var> = <var title="">node</var> . <code title="dom-Node-contains"><a href="#dom-node-contains">contains(<var title="">other</var>)</a></code>
 <dd><p>Returns true if <var title="">other</var> is an
 <a href="#concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</a>
 of <var title="">node</var>, or false otherwise.
</dl>

<p>These are the constants
<code title="dom-Node-compareDocumentPosition"><a href="#dom-node-comparedocumentposition">compareDocumentPosition()</a></code>
returns as mask:

<ul class="brief">
 <li><dfn id="dom-node-document_position_disconnected" title="dom-Node-DOCUMENT_POSITION_DISCONNECTED"><code>DOCUMENT_POSITION_DISCONNECTED</code></dfn> (1);

 <li><dfn id="dom-node-document_position_preceding" title="dom-Node-DOCUMENT_POSITION_PRECEDING"><code>DOCUMENT_POSITION_PRECEDING</code></dfn> (2);

 <li><dfn id="dom-node-document_position_following" title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><code>DOCUMENT_POSITION_FOLLOWING</code></dfn> (4);

 <li><dfn id="dom-node-document_position_contains" title="dom-Node-DOCUMENT_POSITION_CONTAINS"><code>DOCUMENT_POSITION_CONTAINS</code></dfn> (8);

 <li><dfn id="dom-node-document_position_contained_by" title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY"><code>DOCUMENT_POSITION_CONTAINED_BY</code></dfn> (16, 10 in hexadecimal).
</ul>

<p>The <dfn id="dom-node-comparedocumentposition" title="dom-Node-compareDocumentPosition"><code>compareDocumentPosition(<var>other</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>Let <var title="">reference</var> be the <a href="#context-object">context object</a>.
 <li><p>If <var title="">other</var> and <var title="">reference</var> are the
 same object, return zero and terminate these steps.

 <li><p>If <var title="">other</var> and <var title="">reference</var> are not
 in the same <a href="#concept-tree" title="concept-tree">tree</a>, return
 <code title="dom-Node-DOCUMENT_POSITION_DISCONNECTED"><a href="#dom-node-document_position_disconnected">DOCUMENT_POSITION_DISCONNECTED</a></code>
 and terminate these steps.
 <!-- original spec also increments by implementation_specific ... -->

 <li><p>If <var title="">other</var> is an
 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of
 <var title="">reference</var>, return the result of adding
 <code title="dom-Node-DOCUMENT_POSITION_CONTAINS"><a href="#dom-node-document_position_contains">DOCUMENT_POSITION_CONTAINS</a></code>
 to
 <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code>
 and terminate these steps.

 <li><p>If <var title="">other</var> is a
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
 <var title="">reference</var>, return the result of adding
 <code title="dom-Node-DOCUMENT_POSITION_CONTAINED_BY"><a href="#dom-node-document_position_contained_by">DOCUMENT_POSITION_CONTAINED_BY</a></code>
 to
 <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>
 and terminate these steps.

 <li><p>If <var title="">other</var> is
 <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
 <var title="">reference</var> return
 <code title="dom-Node-DOCUMENT_POSITION_PRECEDING"><a href="#dom-node-document_position_preceding">DOCUMENT_POSITION_PRECEDING</a></code>
 and terminate these steps.

 <li><p>Return
 <code title="dom-Node-DOCUMENT_POSITION_FOLLOWING"><a href="#dom-node-document_position_following">DOCUMENT_POSITION_FOLLOWING</a></code>.
</ol>

<!-- AttrExodus compareDocumentPosition() works differently if Attr inherits
     from Node -->

<p>The
<dfn id="dom-node-contains" title="dom-Node-contains"><code>contains(<var title="">other</var>)</code></dfn>
method must return true if <var title="">other</var> is an
<a href="#concept-tree-inclusive-descendant" title="concept-tree-inclusive-descendant">inclusive descendant</a> of
the <a href="#context-object">context object</a>, or false otherwise.

<hr>

<p>The <dfn id="dom-node-nodevalue" title="dom-Node-nodeValue"><code>nodeValue</code></dfn> attribute
must return the following, depending on the <a href="#context-object">context object</a>:

<dl class="switch">
 <!--AttrExodus <dt><code>Attr</code> -->
 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dd><p>The <a href="#context-object">context object</a>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a>.

 <dt>Any other node
 <dd><p>Null.
</dl>

<p>Setting the <code title="dom-Node-nodeValue"><a href="#dom-node-nodevalue">nodeValue</a></code> attribute
must do as described below, depending on the <a href="#context-object">context object</a>:

<dl class="switch">
 <!--AttrExodus <dt><code>Attr</code> -->
 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dd><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
 <a href="#context-object">context object</a>, offset 0, count
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, and
 data new value.

 <dt>Any other node
 <dd><p>Do nothing.
</dl>

<p>The <dfn id="dom-node-textcontent" title="dom-Node-textContent"><code>textContent</code></dfn>
attribute must return the following, depending on the
<a href="#context-object">context object</a>:

<dl class="switch">
 <dt><code><a href="#documentfragment">DocumentFragment</a></code>
 <dt><code><a href="#element">Element</a></code>
 <!--AttrExodus <dt><code>Attr</code> -->
 <dd><p>The concatenation of <a href="#concept-cd-data" title="concept-CD-data">data</a> of all
 the <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a> of the
 <a href="#context-object">context object</a>, in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dd><p>The <a href="#context-object">context object</a>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a>.

 <dt>Any other node
 <dd><p>Null.
</dl>

<p>The <code title="dom-Node-textContent"><a href="#dom-node-textcontent">textContent</a></code> attribute must,
on setting, if the new value is null, act as if it was the empty string
instead, and then do as described below, depending on the <a href="#context-object">context object</a>:

<dl class="switch">
 <dt><code><a href="#documentfragment">DocumentFragment</a></code>
 <dt><code><a href="#element">Element</a></code>
 <!--AttrExodus <dt><code>Attr</code> -->
 <dd>
  <ol>
   <li><p>Let <var title="">node</var> be null.

   <li><p>If new value is not the empty string, set <var title="">node</var> to
   a new <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> whose
   <a href="#concept-cd-data" title="concept-CD-data">data</a> is new value.

   <li><p><a href="#concept-node-replace-all" title="concept-node-replace-all">Replace all</a> with
   <var title="">node</var> within the <a href="#context-object">context object</a>.
  </ol>

 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dd><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
 <a href="#context-object">context object</a>, offset 0, count
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, and
 data new value.

 <dt>Any other node
 <dd><p>Do nothing.
</dl>

<hr>

<dl class="domintro">
 <dt><var title="">node</var> . <code title="dom-Node-normalize"><a href="#dom-node-normalize">normalize()</a></code>
 <dd><p>Concatenates <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> into a
 single <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>.
</dl>

<p>The <dfn id="dom-node-normalize" title="dom-Node-normalize"><code>normalize()</code></dfn> method
must run these steps:</p>

<p>For each <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
<a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of the
<a href="#context-object">context object</a>:

<ol>
 <li><p>Let <var title="">node</var> be the <code><a href="#text">Text</a></code>
 <a href="#concept-node" title="concept-node">node</a>
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>.

 <li><p>Let <var title="">data</var> be the concatenation of the
 <a href="#concept-cd-data" title="concept-CD-data">data</a> of <var title="">node</var>'s
 <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> (excluding itself), in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
 <var title="">node</var>, offset <var title="">node</var>'s
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value,
 count 0, and data <var title="">data</var>.

 <li><p><a href="#concept-node-remove" title="concept-node-remove">Remove</a>
 <var title="">node</var>'s
 <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> (excluding itself), in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
</ol>

<hr>

<dl class="domintro">
 <dt><var title="">clone</var> = <var title="">node</var> .
 <code title="dom-Node-cloneNode"><a href="#dom-node-clonenode">cloneNode</a></code>([<var title="">deep</var>])
 <dd><p>Returns a copy of <var title="">node</var>. If
 <var title="">deep</var> is true or omitted, the copy also includes the
 <var title="">node</var> <a href="#concept-tree-child" title="concept-tree-child">children</a>.

 <dt><var title="">similar</var> = <var title="">node</var> .
 <code title="dom-Node-isEqualNode"><a href="#dom-node-isequalnode">isEqualNode</a></code>(<var title="">other</var>)
 <dd><p>Returns whether <var title="">node</var> and <var title="">other</var>
 have the same properties.
</dl>

<div class="impl">

<p>Specifications may define
<dfn id="concept-node-clone-ext" title="concept-node-clone-ext">cloning steps</dfn> for all or some
<a href="#concept-node" title="concept-node">nodes</a>.

<p>To <dfn id="concept-node-clone" title="concept-node-clone">clone</dfn> a <var title="">node</var>,
optionally with a <i title="">document</i> <var title="">ownerDocument</var> and a
<i title="">clone children flag</i>, run these steps:
<!-- This algorithm is used by dom-Node-cloneNode, dom-Document-importNode,
dom-Range-extractContents, dom-Range-cloneContents -->

<ol>
 <li><p>If <i title="">document</i> is not given let
 <var title="">ownerDocument</var> be <var title="">node</var>'s
 <a href="#concept-node-document" title="concept-node-document">node document</a>.
 <li><p>Let <var title="">copy</var> be a <a href="#concept-node" title="concept-node">node</a>
 that implements the same interfaces as <var title="">node</var>.
 <li>
  <p>If <var title="">copy</var> is a
  <a href="#concept-document" title="concept-document">document</a> set its
  <a href="#concept-node-document" title="concept-node-document">node document</a> to null and set
  <var title="">ownerDocument</var> to <var title="">copy</var>.
  <p>Otherwise, set <var title="">copy</var>'s
  <a href="#concept-node-document" title="concept-node-document">node document</a> to
  <var title="">ownerDocument</var>.
 <li>
  <p>Copy the following, depending on the type of <var title="">node</var>:
  <dl class="switch">
   <dt><code><a href="#element">Element</a></code>
   <dd><p>Its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>,
   <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>, and its
   <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.

   <!--AttrExodus
   <dt><code>Attr</code>
   <dd><p><code title=dom-Attr-value>value</code>
   -->

   <dt><code><a href="#documenttype">DocumentType</a></code>
   <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>,
   <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
   <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.

   <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
   <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a> and
   <a href="#concept-cd-data" title="concept-CD-data">data</a>.

   <dt><code><a href="#text">Text</a></code>
   <dt><code><a href="#comment">Comment</a></code>
   <dd><p>Its <a href="#concept-cd-data" title="concept-CD-data">data</a>.

   <dt>Any other node
   <dd><p>&mdash;
  </dl>

 <li><p>Run any <a href="#concept-node-clone-ext" title="concept-node-clone-ext">cloning steps</a>
 defined for <var title="">node</var> in
 <a href="#other-applicable-specifications">other applicable specifications</a>.

 <li><p>If the <i title="">clone children flag</i> is set,
 <a href="#concept-node-clone" title="concept-node-clone">clone</a> all the
 <a href="#concept-tree-child" title="concept-tree-child">children</a> of <var title="">node</var> and
 append them to <var title="">copy</var>, with <var title="">ownerDocument</var>
 as specified and the <i title="">clone children flag</i> being set.

 <li><p>Return <var title="">copy</var>.
</ol>

<p>The
<dfn id="dom-node-clonenode" title="dom-Node-cloneNode"><code>cloneNode(<var title="">deep</var>)</code></dfn>
method must return a <a href="#concept-node-clone" title="concept-node-clone">clone</a> of the
<a href="#context-object">context object</a>, with the <i title="">clone children flag</i> set
if <var title="">deep</var> is true or omitted.

<p>The
<dfn id="dom-node-isequalnode" title="dom-Node-isEqualNode"><code>isEqualNode(<var title="">node</var>)</code></dfn>
method must return true if all of the following conditions are true, and
false otherwise:

<ul>
 <li><p><var title="">node</var> is not null.
 <li><p><var title="">node</var>'s
 <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code> attribute value is the same
 as the <a href="#context-object">context object</a>'s
 <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code> attribute value.
 <li>
  <p>The following are also equal, depending on <var title="">node</var>:
  <dl class="switch">
   <dt><code><a href="#documenttype">DocumentType</a></code>
   <dd><p>Its <a href="#concept-doctype-name" title="concept-doctype-name">name</a>,
   <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
   <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.

   <dt><code><a href="#element">Element</a></code>
   <dd>
    <p>Its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>,
    <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
    <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>, and its
    number of <a href="#concept-attribute" title="concept-attribute">attributes</a> in its
    <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.

   <!--AttrExodus
   <dt><code>Attr</code>
   <dd><p><code title=dom-Attr-value>value</code>
   -->

   <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
   <dd><p>Its <a href="#concept-pi-target" title="concept-PI-target">target</a> and
   <a href="#concept-cd-data" title="concept-CD-data">data</a>.

   <dt><code><a href="#text">Text</a></code>
   <dt><code><a href="#comment">Comment</a></code>
   <dd><p>Its <a href="#concept-cd-data" title="concept-CD-data">data</a>.

   <dt>Any other node
   <dd><p>&mdash;
  </dl>
 <li><p>If <var title="">node</var> is an <code><a href="#element">Element</a></code>, each
 <a href="#concept-attribute" title="concept-attribute">attribute</a> in its
 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> has an
 <a href="#concept-attribute" title="concept-attribute">attribute</a> with the same
 <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a>,
 <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a>, and
 <a href="#concept-attribute-value" title="concept-attribute-value">value</a> in the
 <a href="#context-object">context object</a>'s
 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
 <li><p><var title="">node</var> has the same number of
 <a href="#concept-tree-child" title="concept-tree-child">children</a> as the
 <a href="#context-object">context object</a>.
 <li><p>Calling <code title="dom-Node-isEqualNode"><a href="#dom-node-isequalnode">isEqualNode()</a></code> on
 each <a href="#concept-tree-child" title="concept-tree-child">child</a> of the
 <a href="#context-object">context object</a>, with the
 <a href="#concept-tree-child" title="concept-tree-child">child</a> of the same index in
 <var title="">node</var> as argument returns true for every
 <a href="#concept-tree-child" title="concept-tree-child">child</a>.
</ul>

</div>

<hr>

<!--
 XXX apparently these algorithms might not be quite correct
 https://bugzilla.mozilla.org/show_bug.cgi?id=312019
 https://bugzilla.mozilla.org/show_bug.cgi?id=505178
-->

<p>To <dfn id="locate-a-namespace-prefix">locate a namespace prefix</dfn> for an <var title="">element</var> using
<var title="">namespace</var> run these steps:

<ol>
 <li><p>If <var title="">element</var>'s
 <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
 <var title="">namespace</var> and its
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
 null return its
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> and
 terminate these steps.

 <li><p>If, <var title="">element</var>
 <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
 <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
 <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> is
 "<code title="">xmlns</code>" and <a href="#concept-attribute-value" title="concept-attribute-value">value</a>
 is <var title="">namespace</var>, then return that
 <a href="#concept-attribute" title="concept-attribute">attribute</a>'s
 <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> and terminate these
 steps.

 <li><p>If <var title="">element</var>'s <a href="#parent-element">parent element</a> is not null,
 return the result of running <a href="#locate-a-namespace-prefix">locate a namespace prefix</a> on that
 <a href="#concept-element" title="concept-element">element</a> using <var title="">namespace</var>.
 Otherwise, return null.
</ol>

<p>To <dfn id="locate-a-namespace">locate a namespace</dfn> for a <var title="">node</var> using
<var title="">prefix</var> depends on the <var title="">node</var>:

<dl class="switch">
 <dt><code><a href="#element">Element</a></code>
 <dd>
  <ol>
   <li><p>If its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
   not null and its
   <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is
   <var title="">prefix</var> return
   <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> and terminate
   these steps.

   <li>
    <p>If it <a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
    <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
    <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a>
    is "<code title="">xmlns</code>" and
    <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
    <var title="">prefix</var>, or whose
    <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> is
    null and <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
    "<code title="">xmlns</code>":

    <ol>
     <li><p>Let <var title="">value</var> be its
     <a href="#concept-attribute-value" title="concept-attribute-value">value</a> if it is not the empty
     string, or null otherwise.

     <li><p>Return <var title="">value</var> and terminate these steps.
    </ol>

   <li><p>If its <a href="#parent-element">parent element</a> is null, return null and
   terminate these steps.

   <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
   its <a href="#parent-element">parent element</a> using <var title="">prefix</var>.
  </ol>

 <!--AttrExodus <code>Attr</code> -->
 <dt><code><a href="#document">Document</a></code>
 <dd>
  <ol>
   <li><p>If its <a href="#document-element">document element</a> is null, return null and
   terminate these steps.

   <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
   its <a href="#document-element">document element</a> using <var title="">prefix</var>.
  </ol>

 <dt><code><a href="#documenttype">DocumentType</a></code>
 <dt><code><a href="#documentfragment">DocumentFragment</a></code>
 <dd><p>Return null.

 <dt>Any other node
 <dd>
  <ol>
   <li><p>If its <a href="#parent-element">parent element</a> is null, return null and
   terminate these steps.

   <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> on
   its <a href="#parent-element">parent element</a> using <var title="">prefix</var>.
  </ol>
</dl>

<p>The
<dfn id="dom-node-lookupprefix" title="dom-Node-lookupPrefix"><code>lookupPrefix(<var title="">namespace</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">namespace</var> is null or the empty string, return null.

 <li>
  <p>Otherwise it depends on the <a href="#context-object">context object</a>:

  <dl class="switch">
   <dt><code><a href="#element">Element</a></code>
   <dd><p>Return the result of
   <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
   for the node using <var title="">namespace</var>.

   <!--AttrExodus <code>Attr</code> -->
   <dt><code><a href="#document">Document</a></code>
   <dd><p>Return the result of
   <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
   for its <a href="#document-element">document element</a>, if that is not null, or null
   otherwise.

   <dt><code><a href="#documenttype">DocumentType</a></code>
   <dt><code><a href="#documentfragment">DocumentFragment</a></code>
   <dd><p>Return null.

   <dt>Any other node
   <dd><p>Return the result of
   <a href="#locate-a-namespace-prefix" title="locate a namespace prefix">locating a namespace prefix</a>
   for its <a href="#parent-element">parent element</a>, or if that is null, null.
  </dl>
</ol>

<p>The
<dfn id="dom-node-lookupnamespaceuri" title="dom-Node-lookupNamespaceURI"><code>lookupNamespaceURI(<var title="">prefix</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">prefix</var> is the empty string, set it to null.

 <li><p>Return the result of running <a href="#locate-a-namespace">locate a namespace</a> for the
 <a href="#context-object">context object</a> using <var title="">prefix</var>.
</ol>

<p>The
<dfn id="dom-node-isdefaultnamespace" title="dom-Node-isDefaultNamespace"><code>isDefaultNamespace(<var title="">namespace</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">namespace</var> is the empty string, set it to null.

 <li><p>Let <var title="">defaultNamespace</var> be the result of running
 <a href="#locate-a-namespace">locate a namespace</a> for the <a href="#context-object">context object</a> using
 null.

 <li><p>Return true if <var title="">defaultNamespace</var> is the same as
 <var title="">namespace</var>, or false otherwise.
</ol>

<hr><!-- Collections -->

<p>The
<dfn id="concept-getelementsbytagname" title="concept-getElementsByTagName">list of elements with local name <var title="">localName</var></dfn>
for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
<code><a href="#nodelist">NodeList</a></code> returned by the following algorithm:
<ol>
 <li><p>If <var title="">localName</var> is "<code>*</code>" (U+002A),
 return a <code><a href="#nodelist">NodeList</a></code> rooted at <var title="">root</var>,
 whose filter matches only <a href="#concept-element" title="concept-element">elements</a>.

 <li>
  <p>Otherwise, if <var title="">root</var>'s
  <a href="#concept-node-document" title="concept-node-document">node document</a> is an
  <a href="#html-document">HTML document</a>, return a <code><a href="#nodelist">NodeList</a></code> rooted at
  <var title="">root</var>, whose filter matches only the following nodes:

  <ul>
   <li><a href="#concept-element" title="concept-element">elements</a> in the
   <a href="#html-namespace">HTML namespace</a> whose
   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
   <var title="">localName</var> <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.

   <li><a href="#concept-element" title="concept-element">elements</a>, <em>not</em> in the
   <a href="#html-namespace">HTML namespace</a>, whose
   <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
   <var title="">localName</var>.
  </ul>

 <li><p>Otherwise, return a <code><a href="#nodelist">NodeList</a></code> rooted at
 <var title="">root</var>, whose filter matches only
 <a href="#concept-element" title="concept-element">elements</a> whose
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
 <var title="">localName</var>.
</ol>
<p>When invoked with the same argument, the same <code><a href="#nodelist">NodeList</a></code>
object may be returned as returned by an earlier call.


<p>The
<dfn id="concept-getelementsbytagnamens" title="concept-getElementsByTagNameNS">list of elements with namespace <var title="">namespace</var> and local name <var title="">localName</var></dfn>
for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
<code><a href="#nodelist">NodeList</a></code> returned by the following algorithm:
<ol>
 <li><p>If <var title="">namespace</var> is the empty string, set it to null.

 <li><p>If both <var title="">namespace</var> and <var title="">localName</var>
 are "<code>*</code>" (U+002A) return a <code><a href="#nodelist">NodeList</a></code> rooted at
 <var title="">root</var>, whose filter matches only
 <a href="#concept-element" title="concept-element">elements</a>.

 <li><p>Otherwise, if just <var title="">namespace</var> is "<code>*</code>"
 (U+002A), return a <code><a href="#nodelist">NodeList</a></code> rooted at
 <var title="">root</var>, whose filter matches only
 <a href="#concept-element" title="concept-element">elements</a> whose
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
 <var title="">localName</var>.

 <li><p>Otherwise, if just <var title="">localName</var> is "<code>*</code>"
 (U+002A), return a <code><a href="#nodelist">NodeList</a></code> rooted at
 <var title="">root</var>, whose filter matches only
 <a href="#concept-element" title="concept-element">elements</a> whose
 <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
 <var title="">namespace</var>.

 <li><p>Otherwise, return a <code><a href="#nodelist">NodeList</a></code> rooted at
 <var title="">root</var>, whose filter matches only
 <a href="#concept-element" title="concept-element">elements</a> whose
 <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
 <var title="">namespace</var> and
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
 <var title="">localName</var>.
</ol>

<p>When invoked with the same arguments, the same <code><a href="#nodelist">NodeList</a></code>
object may be returned as returned by an earlier call.


<p>The
<dfn id="concept-getelementsbyclassname" title="concept-getElementsByClassName">list of elements with class names <var title="">classNames</var></dfn>
for a <a href="#concept-node" title="concept-node">node</a> <var title="">root</var> is the
<code><a href="#nodelist">NodeList</a></code> returned by the following algorithm:
<ol>
 <li>
  <p>Let <var title="">classes</var> be the set of tokens found by
  <a href="#split-a-string-on-spaces" title="split a string on spaces">splitting</a>
  <var title="">classNames</var> on spaces. (Duplicates are ignored.)

 <li>
  <p>If <var title="">classes</var> is the empty set, return an empty
  <code><a href="#nodelist">NodeList</a></code> and terminate these steps.

 <li>
  <p>Return a <code><a href="#nodelist">NodeList</a></code> rooted at <var title="">root</var>,
  whose filter matches only
  <a href="#concept-element" title="concept-element">elements</a> that have all the
  <a href="#concept-class" title="concept-class">classes</a> in <var title="">classes</var>.

  <p>If <var title="">root</var>'s
  <a href="#concept-node-document" title="concept-node-document">node document</a> is in
  <a href="#concept-quirks-mode" title="concept-quirks-mode">quirks mode</a>, then the comparisons
  for the <a href="#concept-class" title="concept-class">classes</a> must be done in an
  <a href="#ascii-case-insensitive">ASCII case-insensitive</a> manner, otherwise, the comparisons
  must be done in a <a href="#case-sensitive">case-sensitive</a> manner.
</ol>
<p>When invoked with the same argument, the same <code><a href="#nodelist">NodeList</a></code>
object may be returned as returned by an earlier call.



<h3 id="interface-document"><span class="secno">5.3 </span>Interface <code><a href="#document">Document</a></code></h3>
<pre class="idl">interface <dfn id="document">Document</dfn> : <a href="#node">Node</a> {
  readonly attribute <a href="#domimplementation">DOMImplementation</a> <a href="#dom-document-implementation" title="dom-Document-implementation">implementation</a>;
  readonly attribute DOMString <a href="#dom-document-url" title="dom-Document-URL">URL</a>;
  readonly attribute DOMString <a href="#dom-document-documenturi" title="dom-Document-documentURI">documentURI</a>;
  readonly attribute DOMString <a href="#dom-document-compatmode" title="dom-Document-compatMode">compatMode</a>;
  readonly attribute DOMString <a href="#dom-document-characterset" title="dom-Document-characterSet">characterSet</a>;
  readonly attribute DOMString <a href="#dom-document-contenttype" title="dom-Document-contentType">contentType</a>;

  readonly attribute <a href="#documenttype">DocumentType</a>? <a href="#dom-document-doctype" title="dom-Document-doctype">doctype</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-document-documentelement" title="dom-Document-documentElement">documentElement</a>;
  <a href="#nodelist">NodeList</a> <a href="#dom-document-getelementsbytagname" title="dom-Document-getElementsByTagName">getElementsByTagName</a>(DOMString <var title="">qualifiedName</var>);
  <a href="#nodelist">NodeList</a> <a href="#dom-document-getelementsbytagnamens" title="dom-Document-getElementsByTagNameNS">getElementsByTagNameNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  <a href="#nodelist">NodeList</a> <a href="#dom-document-getelementsbyclassname" title="dom-Document-getElementsByClassName">getElementsByClassName</a>(DOMString <var title="">classNames</var>);
  <a href="#element">Element</a>? <a href="#dom-document-getelementbyid" title="dom-Document-getElementById">getElementById</a>(DOMString <var title="">elementId</var>);

  <a href="#element">Element</a> <a href="#dom-document-createelement" title="dom-Document-createElement">createElement</a>(DOMString <var title="">localName</var>);
  <a href="#element">Element</a> <a href="#dom-document-createelementns" title="dom-Document-createElementNS">createElementNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">qualifiedName</var>);
  <a href="#documentfragment">DocumentFragment</a> <a href="#dom-document-createdocumentfragment" title="dom-Document-createDocumentFragment">createDocumentFragment</a>();
  <a href="#text">Text</a> <a href="#dom-document-createtextnode" title="dom-Document-createTextNode">createTextNode</a>(DOMString <var title="">data</var>);
  <a href="#comment">Comment</a> <a href="#dom-document-createcomment" title="dom-Document-createComment">createComment</a>(DOMString <var title="">data</var>);
  <a href="#processinginstruction">ProcessingInstruction</a> <a href="#dom-document-createprocessinginstruction" title="dom-Document-createProcessingInstruction">createProcessingInstruction</a>(DOMString <var title="">target</var>, DOMString <var title="">data</var>);<!--
  CDATASection createCDATASection(DOMString data);
  EntityReference createEntityReference(DOMString name);
  <span>Attr</span> <span title=dom-Document-createAttribute>createAttribute</span>(DOMString name);
  <span>Attr</span> <span title=dom-Document-createAttributeNS>createAttributeNS</span>(DOMString namespace, DOMString qualifiedName);
    If adding this, search for [createAttribute]-->

  <a href="#node">Node</a> <a href="#dom-document-importnode" title="dom-Document-importNode">importNode</a>(<a href="#node">Node</a> <var title="">node</var>, optional boolean <var title="">deep</var>);
  <a href="#node">Node</a> <a href="#dom-document-adoptnode" title="dom-Document-adoptNode">adoptNode</a>(<a href="#node">Node</a> <var title="">node</var>);

  <a href="#event">Event</a> <a href="#dom-document-createevent" title="dom-Document-createEvent">createEvent</a>(DOMString <var title="">eventInterfaceName</var>);

  <a href="#range">Range</a> <a href="#dom-document-createrange" title="dom-Document-createRange">createRange</a>();

  <a href="#nodeiterator">NodeIterator</a> <a href="#dom-document-createnodeiterator" title="dom-Document-createNodeIterator">createNodeIterator</a>(<a href="#node">Node</a> <var title="">root</var>, optional unsigned long <var title="">whatToShow</var>, optional <a href="#nodefilter">NodeFilter</a>? <var title="">filter</var>);
  <a href="#treewalker">TreeWalker</a> <a href="#dom-document-createtreewalker" title="dom-Document-createTreeWalker">createTreeWalker</a>(<a href="#node">Node</a> <var title="">root</var>, optional unsigned long <var title="">whatToShow</var>, optional <a href="#nodefilter">NodeFilter</a>? <var title="">filter</var>);

  // NEW
  void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
};

interface <dfn id="xmldocument">XMLDocument</dfn> : <a href="#document">Document</a> {};</pre>

<p><code><a href="#document">Document</a></code> <a href="#concept-node" title="concept-node">nodes</a> are simply
known as <dfn id="concept-document" title="concept-document">documents</dfn>.

<p>Each <a href="#concept-document" title="concept-document">document</a> has an associated
<dfn id="concept-document-encoding" title="concept-document-encoding">encoding</dfn>,
<dfn id="concept-document-content-type" title="concept-document-content-type">content type</dfn>, and
<dfn id="concept-document-url" title="concept-document-url">URL</dfn>.

<p>Unless explicitly given when a
<a href="#concept-document" title="concept-document">document</a> is created its
<a href="#concept-document-encoding" title="concept-document-encoding">encoding</a> is
<code title="">utf-8</code>, its
<a href="#concept-document-content-type" title="concept-document-content-type">content type</a> is
"<code title="">application/xml</code>", and its
<a href="#concept-document-url" title="concept-document-url">URL</a> is
"<code title="">about:blank</code>".

<p>A <a href="#concept-document" title="concept-document">document</a> is assumed to be an
<dfn id="xml-document">XML document</dfn> unless it is flagged as being an
<dfn id="html-document">HTML document</dfn>. Whether a
<a href="#concept-document" title="concept-document">document</a> is an
<a href="#html-document">HTML document</a> or an <a href="#xml-document">XML document</a> affects the
behavior of certain APIs.

<p>A <a href="#concept-document" title="concept-document">document</a> is always set to one of
three modes: <dfn id="concept-no-quirks-mode" title="concept-no-quirks-mode">no-quirks mode</dfn>, the
default; <dfn id="concept-quirks-mode" title="concept-quirks-mode">quirks mode</dfn>, used typically
for legacy documents; and
<dfn id="concept-limited-quirks-mode" title="concept-limited-quirks-mode">limited-quirks mode</dfn>, also known
as "almost standards" mode. Unless
<a href="#other-applicable-specifications">other applicable specifications</a> define otherwise, a
<a href="#concept-document" title="concept-document">document</a> must be in
<a href="#concept-no-quirks-mode" title="concept-no-quirks-mode">no-quirks mode</a>.

<p class="note">The mode is only ever changed from the default if the
<a href="#concept-document" title="concept-document">document</a> is created by the
<a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#html-parser">HTML parser</a>, based on the presence,
absence, or value of the DOCTYPE string.
<a class="informative" href="#refsHTML">[HTML]</a>

<hr>

<dl class="domintro">
 <dt><var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code>
 <dd><p>Returns the associated <code><a href="#domimplementation">DOMImplementation</a></code> object.

 <dt><var title="">document</var> . <code title="dom-Document-URL"><a href="#dom-document-url">URL</a></code>
 <dt><var title="">document</var> . <code title="dom-Document-documentURI"><a href="#dom-document-documenturi">documentURI</a></code>
 <dd><p>Returns the <a href="#concept-document-url" title="concept-document-url">URL</a>.

 <dt><var title="">document</var> . <code title="dom-Document-compatMode"><a href="#dom-document-compatmode">compatMode</a></code>
 <dd>
  <p>Returns the string "<code title="">CSS1Compat</code>" if
  <var title="">document</var> is in
  <a href="#concept-no-quirks-mode" title="concept-no-quirks-mode">no-quirks mode</a> or
  <a href="#concept-limited-quirks-mode" title="concept-limited-quirks-mode">limited-quirks mode</a>, and
  "<code title="">BackCompat</code>", if <var title="">document</var> is in
  <a href="#concept-quirks-mode" title="concept-quirks-mode">quirks mode</a>.

 <dt><var title="">document</var> . <code title="dom-Document-characterSet"><a href="#dom-document-characterset">characterSet</a></code>
 <dd><p>Returns the <a href="#concept-document-encoding" title="concept-document-encoding">encoding</a>.

 <dt><var title="">document</var> . <code title="dom-Document-contentType"><a href="#dom-document-contenttype">contentType</a></code>
 <dd><p>Returns the
 <a href="#concept-document-content-type" title="concept-document-content-type">content type</a>.
</dl>

<p>The
<dfn id="dom-document-implementation" title="dom-Document-implementation"><code>implementation</code></dfn>
attribute must return the <code><a href="#domimplementation">DOMImplementation</a></code> object that is
associated with the <a href="#concept-document" title="concept-document">document</a>.

<p>The <dfn id="dom-document-url" title="dom-Document-URL"><code>URL</code></dfn> and
<dfn id="dom-document-documenturi" title="dom-Document-documentURI"><code>documentURI</code></dfn>
attributes must return the <a href="#concept-document-url" title="concept-document-url">URL</a>.

<p>The <dfn id="dom-document-compatmode" title="dom-Document-compatMode"><code>compatMode</code></dfn> IDL
attribute must return the literal string "<code title="">CSS1Compat</code>"
unless the <a href="#context-object">context object</a> is in
<a href="#concept-quirks-mode" title="concept-quirks-mode">quirks mode</a>, in which case it must
instead return the literal string "<code title="">BackCompat</code>".

<p>The <dfn id="dom-document-characterset" title="dom-Document-characterSet"><code>characterSet</code></dfn>
attribute must return the <a href="#preferred-mime-name">preferred MIME name</a> of the
<a href="#concept-document-encoding" title="concept-document-encoding">encoding</a>.

<p>The <dfn id="dom-document-contenttype" title="dom-Document-contentType"><code>contentType</code></dfn>
attribute must return the
<a href="#concept-document-content-type" title="concept-document-content-type">content type</a>.

<hr>

<dl class="domintro">
 <dt><var title="">document</var> . <code title="dom-Document-doctype"><a href="#dom-document-doctype">doctype</a></code>
 <dd><p>Returns the <a href="#concept-doctype" title="concept-doctype">doctype</a> or null if
 there is none.

 <dt><var title="">document</var> . <code title="dom-Document-documentElement"><a href="#dom-document-documentelement">documentElement</a></code>
 <dd><p>Returns the <a href="#document-element">document element</a>.

 <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByTagName"><a href="#dom-document-getelementsbytagname">getElementsByTagName(<var>localName</var>)</a></code>

 <dd>
  <p>If <var>localName</var> is "<code title="">*</code>" returns a
  <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a>.

  <p>Otherwise, returns a <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a> whose
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  <var title="">localName</var>. (Matches case-insensitively against
  <a href="#concept-element" title="concept-element">elements</a> in the
  <a href="#html-namespace">HTML namespace</a> within an <a href="#html-document">HTML document</a>.)

 <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByTagName"><a href="#dom-document-getelementsbytagname">getElementsByTagNameNS(<var>namespace</var>, <var>localName</var>)</a></code>

 <dd>
  <p>If <var>namespace</var> and <var>localName</var> are
  "<code title="">*</code>" returns a <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a>.

  <p>If only <var>namespace</var> is "<code title="">*</code>" returns a
  <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a> whose
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  <var title="">localName</var>.

  <p>If only <var>localName</var> is "<code title="">*</code>" returns a
  <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a> whose
  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  <var title="">namespace</var>.

  <p>Otherwise, returns a <code><a href="#nodelist">NodeList</a></code> of all
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>
  <a href="#concept-element" title="concept-element">elements</a> whose
  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  <var title="">namespace</var> and
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  <var title="">localName</var>.

 <dt><var title="">collection</var> = <var title="">document</var> . <code title="dom-Document-getElementsByClassName"><a href="#dom-document-getelementsbyclassname">getElementsByClassName(<var>classes</var>)</a></code>
 <dt><var title="">collection</var> = <var title="">element</var> . <code title="dom-Element-getElementsByClassName"><a href="#dom-element-getelementsbyclassname">getElementsByClassName(<var>classes</var>)</a></code>
 <dd>
  <p>Returns a <code><a href="#nodelist">NodeList</a></code> of the
  <a href="#concept-element" title="concept-element">elements</a> in the object on which
  the method was invoked (a <a href="#concept-document" title="concept-document">document</a> or
  an <a href="#concept-element" title="concept-element">element</a>) that have all the classes
  given by <var title="">classes</var>.
  <p>The <var title="">classes</var> argument is interpreted as a
  space-separated list of classes.

 <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-getElementById"><a href="#dom-document-getelementbyid">getElementById(<var title="">elementId</var>)</a></code>
 <dd><p>Returns the first <a href="#concept-element" title="concept-element">element</a> in
 <var title="">document</var> with the given <a href="#concept-id" title="concept-id">ID</a>.
</dl>

<p>The <dfn id="dom-document-doctype" title="dom-Document-doctype"><code>doctype</code></dfn> attribute
must return the <a href="#concept-tree-child" title="concept-tree-child">child</a> of the
<a href="#concept-document" title="concept-document">document</a> that is a
<a href="#concept-doctype" title="concept-doctype">doctype</a>, or null otherwise.

<p>The
<dfn id="dom-document-documentelement" title="dom-Document-documentElement"><code>documentElement</code></dfn>
attribute must return the <a href="#document-element">document element</a>.

<p>The
<dfn id="dom-document-getelementsbytagname" title="dom-Document-getElementsByTagName"><code>getElementsByTagName(<var title="">localName</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbytagname" title="concept-getElementsByTagName">list of elements with local name <var title="">localName</var></a>
for the <a href="#context-object">context object</a>.

<p class="note">Thus, in an <a href="#html-document">HTML document</a>,
<code title="">document.getElementsByTagName("FOO")</code> will match
<code title="">FOO</code> elements that are not in the
<a href="#html-namespace">HTML namespace</a>, and <code title="">foo</code> elements that are in
the <a href="#html-namespace">HTML namespace</a>, but not <code title="">FOO</code> elements
that are in the <a href="#html-namespace">HTML namespace</a>.


<p>The
<dfn id="dom-document-getelementsbytagnamens" title="dom-Document-getElementsByTagNameNS"><code>getElementsByTagNameNS(<var title="">namespace</var>, <var title="">localName</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbytagnamens" title="concept-getElementsByTagNameNS">list of elements with namespace <var title="">namespace</var> and local name <var title="">localName</var></a>
for the <a href="#context-object">context object</a>.


<p>The
<dfn id="dom-document-getelementsbyclassname" title="dom-Document-getElementsByClassName"><code>getElementsByClassName(<var>classNames</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbyclassname" title="concept-getElementsByClassName">list of elements with class names <var title="">classNames</var></a>
for the <a href="#context-object">context object</a>.

<div class="example">
 <p>Given the following XHTML fragment:

 <pre>&lt;div id="example"&gt;
  &lt;p id="p1" class="aaa bbb"/&gt;
  &lt;p id="p2" class="aaa ccc"/&gt;
  &lt;p id="p3" class="bbb ccc"/&gt;
&lt;/div&gt;</pre>

 <p>A call to
 <code title="">document.getElementById('example').getElementsByClassName('aaa')</code>
 would return a <code><a href="#nodelist">NodeList</a></code> with the two paragraphs
 <code title="">p1</code> and <code title="">p2</code> in it.

 <p>A call to
 <code title="">getElementsByClassName('ccc&nbsp;bbb')</code>
 would only return one node, however, namely <code title="">p3</code>. A call to
 <code title="">document.getElementById('example').getElementsByClassName('bbb&nbsp;&nbsp;ccc&nbsp;')</code>
 would return the same thing.

 <p>A call to
 <code title="">getElementsByClassName('aaa,bbb')</code>
 would return no nodes; none of the elements above are in the
 <code title="">aaa,bbb</code> class.
</div>

<!-- v2:
>         * xGetParentElementByClassName(rootElement, className, tagName) -
> Navigates upwards until we hit a parent element with the given class name and
> optional tag name.
-->

<p>The
<dfn id="dom-document-getelementbyid" title="dom-Document-getElementById"><code>getElementById(<var title="">elementId</var>)</code></dfn>
method must return the first <a href="#concept-element" title="concept-element">element</a>, in
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>, within the
<a href="#context-object">context object</a>'s <a href="#concept-tree" title="concept-tree">tree</a>, whose
<a href="#concept-id" title="concept-ID">ID</a> is <var title="">elementId</var>, or null if
there is none.

<hr>

<dl class="domintro">
 <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-createElement"><a href="#dom-document-createelement">createElement(<var>localName</var>)</a></code>
 <dd>
  <p>Returns an <a href="#concept-element" title="concept-element">element</a> in the
  <a href="#html-namespace">HTML namespace</a> with <var title="">localName</var> as
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>. (In an
  <a href="#html-document">HTML document</a> <var title="">localName</var> is lowercased.)

  <p>If <var title="">localName</var> does not match the
  <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  exception will be thrown.

 <dt><var title="">element</var> = <var title="">document</var> . <code title="dom-Document-createElement"><a href="#dom-document-createelement">createElementNS(<var>namespace</var>, <var>qualifiedName</var>)</a></code>

 <dd>
  <p>Returns an <a href="#concept-element" title="concept-element">element</a> with
  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>
  <var title="">namespace</var>. Its
  <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> will
  be everything before "<code title="">:</code>" (U+003E) in
  <var title="">qualifiedName</var> or null. Its
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> will be
  everything after "<code title="">:</code>" (U+003E) in
  <var title="">qualifiedName</var> or <var title="">qualifiedName</var>.

  <p>If <var title="">localName</var> does not match the
  <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  exception will be thrown.

  <p>If one of the following conditions is true a
  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception
  will be thrown:

  <ul>
   <li><var title="">localName</var> does not match the
   <code class="external"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production.
   <li><a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">Namespace prefix</a>
   is not null and <var title="">namespace</var> is the empty string.
   <li><a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">Namespace prefix</a>
   is "<code title="">xml</code>" and <var title="">namespace</var> is not the
   <a href="#xml-namespace">XML namespace</a>.
   <li><var title="">qualifiedName</var> or
   <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>
   is "<code title="">xmlns</code>" and <var title="">namespace</var> is not the
   <a href="#xmlns-namespace">XMLNS namespace</a>.
   <li><var title="">namespace</var> is the <a href="#xmlns-namespace">XMLNS namespace</a> and
   neither <var title="">qualifiedName</var> nor
   <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>
   is "<code title="">xmlns</code>".
  </ul>

 <dt><var title="">documentFragment</var> = <var title="">document</var> . <code title="dom-Document-createDocumentFragment"><a href="#dom-document-createdocumentfragment">createDocumentFragment()</a></code>
 <dd><p>Returns a <code><a href="#documentfragment">DocumentFragment</a></code>
 <a href="#concept-node" title="concept-node">node</a>.

 <dt><var title="">text</var> = <var title="">document</var> . <code title="dom-Document-createTextNode"><a href="#dom-document-createtextnode">createTextNode(<var>data</var>)</a></code>
 <dd><p>Returns a <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>
 whose <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.

 <dt><var title="">comment</var> = <var title="">document</var> . <code title="dom-Document-createComment"><a href="#dom-document-createcomment">createComment(<var>data</var>)</a></code>
 <dd><p>Returns a <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>
 whose <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.

 <dt><var title="">processingInstruction</var> = <var title="">document</var> . <code title="dom-Document-createProcessingInstruction"><a href="#dom-document-createprocessinginstruction">createProcessingInstruction(<var>target</var>, <var>data</var>)</a></code>
 <dd>
  <p>Returns a <code><a href="#processinginstruction">ProcessingInstruction</a></code>
  <a href="#concept-node" title="concept-node">node</a> whose
  <a href="#concept-pi-target" title="concept-PI-target">target</a> is <var title="">target</var> and
  <a href="#concept-cd-data" title="concept-CD-data">data</a> is <var title="">data</var>.
  <p>If <var title="">target</var> does not match the
  <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production an
  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  exception will be thrown.
  <p>If <var title="">data</var> contains "<code title="">?&gt;</code>" an
  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  exception will be thrown.
</dl>

<p>The <dfn id="dom-document-createelement" title="dom-Document-createElement"><code>createElement(<var title="">localName</var>)</code></dfn> method must run the these steps:

<ol>
 <li><p>If <var title="">localName</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><p>If the <a href="#context-object">context object</a> is an <a href="#html-document">HTML document</a>,
 let <var title="">localName</var> be
 <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.
 <!-- XXX why restrict this to HTML documents? -->

 <li><p>Return a new <a href="#concept-element" title="concept-element">element</a> with no
 attributes, <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> set to
 the <a href="#html-namespace">HTML namespace</a>,
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> set to
 <var title="">localName</var>, and
 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
 <a href="#context-object">context object</a>.
</ol>

<p>The
<dfn id="dom-document-createelementns" title="dom-Document-createElementNS"><code>createElementNS(<var title="">namespace</var>, <var title="">qualifiedName</var>)</code></dfn>
method must run these steps:
<ol>
 <li><p>If <var title="">namespace</var> is the empty string, set it to null.

 <li><p>If <var title="">qualifiedName</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.
 <li><p>If <var title="">qualifiedName</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <li><p>If <var title="">qualifiedName</var> contains a "<code>:</code>"
 (U+003E), then split the string on it and let <var title="">prefix</var> be
 the part before and <var title="">localName</var> the part after. Otherwise,
 let <var title="">prefix</var> be null and <var title="">localName</var> be
 <var title="">qualifiedName</var>.
 <li><p>If <var title="">prefix</var> is not null and
 <var title="">namespace</var> is null, <a href="#concept-throw" title="concept-throw">throw</a>
 a "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <li><p>If <var title="">prefix</var> is "<code title="">xml</code>" and
 <var title="">namespace</var> is not the <a href="#xml-namespace">XML namespace</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <li><p>If <var title="">qualifiedName</var> or <var title="">prefix</var> is
 "<code title="">xmlns</code>" and <var title="">namespace</var> is not the
 <a href="#xmlns-namespace">XMLNS namespace</a>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <li><p>If <var title="">namespace</var> is the <a href="#xmlns-namespace">XMLNS namespace</a>
 and neither <var title="">qualifiedName</var> nor <var title="">prefix</var> is
 "<code title="">xmlns</code>", <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <li><p>Return a new <a href="#concept-element" title="concept-element">element</a> with no
 attributes, <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> set to
 <var title="">namespace</var>,
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> set to
 <var title="">prefix</var>,
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> set to
 <var title="">localName</var>, and
 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
 <a href="#context-object">context object</a>.
</ol>

<p>The
<dfn id="dom-document-createdocumentfragment" title="dom-Document-createDocumentFragment"><code>createDocumentFragment()</code></dfn>
method must return a new <code><a href="#documentfragment">DocumentFragment</a></code>
<a href="#concept-node" title="concept-node">node</a> with its
<a href="#concept-node-document" title="concept-node-document">node document</a> set to the
<a href="#context-object">context object</a>.

<p>The
<dfn id="dom-document-createtextnode" title="dom-Document-createTextNode"><code>createTextNode(<var title="">data</var>)</code></dfn>
method must return a new <code><a href="#text">Text</a></code>
<a href="#concept-node" title="concept-node">node</a> with its
<a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var> and
<a href="#concept-node-document" title="concept-node-document">node document</a> set to the
<a href="#context-object">context object</a>.
<p class="note">No check is performed that <var title="">data</var> consists of
characters that match the <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production.

<p>The
<dfn id="dom-document-createcomment" title="dom-Document-createComment"><code>createComment(<var title="">data</var>)</code></dfn>
method must return a new <code><a href="#comment">Comment</a></code>
<a href="#concept-node" title="concept-node">node</a> with its
<a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var> and
<a href="#concept-node-document" title="concept-node-document">node document</a> set to the
<a href="#context-object">context object</a>.
<p class="note">No check is performed that <var title="">data</var> consists of
characters that match the <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production
or that it contains two adjacent hyphens or ends with a hyphen.

<p>The <dfn id="dom-document-createprocessinginstruction" title="dom-Document-createProcessingInstruction"><code>createProcessingInstruction(<var title="">target</var>, <var title="">data</var>)</code></dfn> method must run these steps:

<ol>
 <li><p>If <var title="">target</var> does not match the
 <!--<code data-anolis-spec=xml>PITarget</code>-->
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps. <!-- DOM3 does not check for "xml" -->

 <li><p>If <var title="">data</var> contains the string
 "<code title="">?&gt;</code>", <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps. <!-- Gecko does this. -->

 <!--<li><p>If <var title>target</var> contains a U+003A COLON (":")
 character, <span title=concept-throw>throw</span> a
 "<code>NamespaceError</code>" exception and terminate these steps.-->
 <!-- DOM3 didn't check this -->

 <li><p>Return a new <code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <a href="#concept-node" title="concept-node">node</a>, with
 <a href="#concept-pi-target" title="concept-PI-target">target</a> set to <var title="">target</var>,
 <a href="#concept-cd-data" title="concept-CD-data">data</a> set to <var title="">data</var>, and
 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
 <a href="#context-object">context object</a>.
</ol>

<p class="note">No check is performed that <var title="">target</var> contains
"<code title="">xml</code>" or "<code title="">:</code>", or that
<var title="">data</var> contains characters that match the
<code class="external"><a href="http://www.w3.org/TR/xml/#NT-Char">Char</a></code> production.

<!--
[createAttribute]
<p>The <dfn title=dom-Document-createAttribute><code>createAttribute(<var title>name</var>)</code></dfn> method must run these steps:
<ol>
 <li><p>If <var title>name</var> does not match the <code data-anolis-spec=xml>Name</code> production in XML,
 <span title=concept-throw>throw</span> an
 "<code>InvalidCharacterError</code>"
 exception and terminate these steps.
 <li><p>Return a new <code>Attr</code> node with its <code title=dom-Node-namespaceURI>namespaceURI</code> set to null, <code title=dom-Node-prefix>prefix</code> set to null, <code title=dom-Node-localName>localName</code> set to <var title>name</var>, and <span title=concept-node-document>node document</span> set to the <span>context object</span>.
</ol>-->
<!-- this is different from DOM3 -->
<!--<p class=note>No check is performed that the local name will match the <code
data-anolis-spec=xmlns>NCName</code> production in Namespaces in XML.-->

<hr>

<dl class="domintro">
 <dt><var title="">clone</var> = <var title="">document</var> . <code title="dom-Document-importNode"><a href="#dom-document-importnode">importNode(<var>node</var> [, <var>deep</var>])</a></code>
 <dd>
 <dd>
  <p>Returns a copy of <var title="">node</var>. If
  <var title="">deep</var> is true or omitted, the copy also includes the
  <var title="">node</var> <a href="#concept-tree-child" title="concept-tree-child">children</a>.

  <p>If <var title="">node</var> is a
  <a href="#concept-document" title="concept-document">document</a> throws a
  "<code><a href="#notsupportederror">NotSupportedError</a></code>"
  exception.

 <dt><var title="">node</var> = <var title="">document</var> . <code title="dom-Document-adoptNode"><a href="#dom-document-adoptnode">adoptNode(<var>node</var>)</a></code>

 <dd>
  <p>Moves <var title="">node</var> from another
  <a href="#concept-document" title="concept-document">document</a> and returns it.

  <p>If <var title="">node</var> is a
  <a href="#concept-document" title="concept-document">document</a> throws a
  "<code><a href="#notsupportederror">NotSupportedError</a></code>"
  exception.
</dl>

<p>The
<dfn id="dom-document-importnode" title="dom-Document-importNode"><code>importNode(<var title="">node</var>, <var title="">deep</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">node</var> is a
 <a href="#concept-document" title="concept-document">document</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notsupportederror">NotSupportedError</a></code>" exception and terminate these steps.

 <li><p>Return a <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
 <var title="">node</var>, with <i title="">document</i>
 <a href="#context-object">context object</a> and the <i title="">clone children flag</i> set if
 <var title="">deep</var> is true or omitted.
</ol>

<p>To <dfn id="concept-node-adopt" title="concept-node-adopt">adopt</dfn> a <var title="">node</var>,
with an <var title="">ownerDocument</var>, run these steps:

<ol>
 <li><p>If <var title="">node</var> is an
 <a href="#concept-element" title="concept-element">element</a>, it is
 <a href="#affected-by-a-base-url-change">affected by a base URL change</a>.

 <li><p>If <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not null, remove
 <var title="">node</var> from its
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>Set <a href="#concept-node-document" title="concept-node-document">node document</a> for
 <var title="">node</var> and all its
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a>
 <!--AttrExodus as well as any associated <code>Attr</code> nodes-->
 to <var title="">ownerDocument</var>.
</ol>

<p>The
<dfn id="dom-document-adoptnode" title="dom-Document-adoptNode"><code>adoptNode(<var title="">node</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">node</var> is a
 <a href="#concept-document" title="concept-document">document</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notsupportederror">NotSupportedError</a></code>" exception and terminate these steps.

 <li><p><a href="#concept-node-adopt" title="concept-node-adopt">Adopt</a> <var title="">node</var>
 with the <a href="#context-object">context object</a> and return it.
</ol>

<hr>

<dl class="domintro">
 <dt><var title="">event</var> = <var title="">document</var> . <code title="dom-Document-createEvent"><a href="#dom-document-createevent">createEvent(<var>eventInterfaceName</var>)</a></code>
 <dd>
  <p>Returns an <a href="#concept-event" title="concept-event">event</a> using an interface
  for which the interface name is a case-insensitive match for
  <var title="">eventInterfaceName</var>.
  <!-- No need to mention "htmlevents" et al here. -->
</dl>

<p>When the <dfn id="dom-document-createevent" title="dom-Document-createEvent"><code>createEvent(<var>eventInterfaceName</var>)</code></dfn> methed is invoked these steps must be run:

<ol>
 <li>
  <p>If <var title="">eventInterfaceName</var> is an
  <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for any of the strings in the first
  column in the following table, let <var title="">eventInterfaceName</var> be the
  string in the second column on the same row as the matching string:</p>
  <table>
  <thead>
   <tr><th>Input interface <th>Replacement interface
  <tbody>
   <tr><td>"<code title="">htmlevents</code>"<td>"<code title="">event</code>"
   <tr><td>"<code title="">mouseevents</code>"<td>"<code title="">mouseevent</code>"
   <tr><td>"<code title="">mutationevents</code>"<td>"<code title="">mutationevent</code>"
   <tr><td>"<code title="">uievents</code>"<td>"<code title="">uievent</code>"
  </table>
  <!-- XXX WebKit/Gecko (IE?) support "events" -> "event". Add it or make sure it's not supported? -->
 </li>
 <li><p>If <var title="">eventInterfaceName</var> is <em>not</em> an
 <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for "<code title="">event</code>" or
 for the name of an interface that inherits from the <code><a href="#event">Event</a></code>
 interface and is supported by the user agent,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#notsupportederror">NotSupportedError</a></code>" and terminate these steps.
 <li><p>Create an <a href="#concept-event" title="concept-event">event</a> implementing the
 interface whose name <var title="">eventInterfaceName</var> is an
 <a href="#ascii-case-insensitive">ASCII case-insensitive</a> match for and return it.
</ol>

<p class="note">This method is pretty much obsolete as
<a href="#concept-event" title="concept-event">events</a> have constructors these days, but
needs to be supported for legacy content. Tough.

<hr>

<dl class="domintro">
 <dt><var title="">event</var> = <var title="">document</var> . <code title="dom-Document-createRange"><a href="#dom-document-createrange">createRange()</a></code>
 <dd><p>Returns a new <a href="#concept-range" title="concept-range">range</a>.
</dl>

<p>The <dfn id="dom-document-createrange" title="dom-Document-createRange"><code>createRange()</code></dfn>
method must return a new <a href="#concept-range" title="concept-range">range</a> with
(<a href="#context-object">context object</a>, 0) as its
<a href="#concept-range-start" title="concept-range-start">start</a> and
<a href="#concept-range-end" title="concept-range-end">end</a>.

<hr>

<p>When the
<dfn id="dom-document-createnodeiterator" title="dom-Document-createNodeIterator"><code>createNodeIterator(<var>root</var>, <var>whatToShow</var>, <var>filter</var>)</code></dfn>
method is invoked these steps must be run:

<ol>
 <li><p>Create a <code><a href="#nodeiterator">NodeIterator</a></code> object.
 <li><p>Set <a href="#concept-traversal-root" title="concept-traversal-root">root</a> and initialize
 the <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code>
 attribute to the <var title="">root</var> argument.
 <li><p>Set <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> to
 the <var title="">whatToShow</var> argument, or to
 <code title="dom-NodeFilter-SHOW_ALL"><a href="#dom-nodefilter-show_all">SHOW_ALL</a></code> if omitted.
 <li><p>Set <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> to
 <var title="">filter</var>, or to null if omitted.
 <li><p>Return the newly created <code><a href="#nodeiterator">NodeIterator</a></code> object.
</ol>

<p>When the
<dfn id="dom-document-createtreewalker" title="dom-Document-createTreeWalker"><code>createTreeWalker(<var>root</var>, <var>whatToShow</var>, <var>filter</var>)</code></dfn>
method is invoked these steps must be run:

<ol>
 <li><p>Create a <code><a href="#treewalker">TreeWalker</a></code> object.
 <li><p>Set <a href="#concept-traversal-root" title="concept-traversal-root">root</a> and initialize
 the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute to
 the <var title="">root</var> argument.
 <li><p>Set <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> to
 the <var title="">whatToShow</var> argument, or to
 <code title="dom-NodeFilter-SHOW_ALL"><a href="#dom-nodefilter-show_all">SHOW_ALL</a></code> if omitted.
 <li><p>Set <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> to
 <var title="">filter</var>, or to null if omitted.
 <li><p>Return the newly created <code><a href="#treewalker">TreeWalker</a></code> object.
</ol>



<h4 id="interface-domimplementation"><span class="secno">5.3.1 </span>Interface <code><a href="#domimplementation">DOMImplementation</a></code></h4>
<p>User agents must create a <code><a href="#domimplementation">DOMImplementation</a></code> object whenever
a <a href="#concept-document" title="concept-document">document</a> is created and associate it
with that <a href="#concept-document" title="concept-document">document</a>.

<pre class="idl">interface <dfn id="domimplementation">DOMImplementation</dfn> {
  boolean <a href="#dom-domimplementation-hasfeature" title="dom-DOMImplementation-hasFeature">hasFeature</a>(DOMString feature, [TreatNullAs=EmptyString] DOMString version);

  <a href="#documenttype">DocumentType</a> <a href="#dom-domimplementation-createdocumenttype" title="dom-DOMImplementation-createDocumentType">createDocumentType</a>(DOMString qualifiedName, DOMString publicId, DOMString systemId);
  <a href="#xmldocument">XMLDocument</a> <a href="#dom-domimplementation-createdocument" title="dom-DOMImplementation-createDocument">createDocument</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">qualifiedName</var>, <a href="#documenttype">DocumentType</a>? <var title="">doctype</var>);
  <a href="#document">Document</a> <a href="#dom-domimplementation-createhtmldocument" title="dom-DOMImplementation-createHTMLDocument">createHTMLDocument</a>(DOMString title);
};</pre>

<dl class="domintro">
 <dt><var title="">hasSupport</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-hasFeature"><a href="#dom-domimplementation-hasfeature">hasFeature</a></code>(
 <var title="">feature</var>, <var title="">version</var> )

 <dd>
  <p>Returns whether the user agent supports the version <var title="">version</var> of <var title="">feature</var>. The empty string means any
  version.
</dl>

<div class="impl">

<p>The <dfn id="dom-domimplementation-hasfeature" title="dom-DOMImplementation-hasFeature"><code>hasFeature(<var title="">feature</var>, <var title="">version</var>)</code></dfn> method must return
true if the user agent <a href="#concept-support-domfeatureversion" title="concept-support-DOMfeatureversion">supports</a>
the (<var title="">feature</var>, <var title="">version</var>) tuple and false
otherwise.

</div>

<hr>

<dl class="domintro">
 <dt><var title="">doctype</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-createDocumentType"><a href="#dom-domimplementation-createdocumenttype">createDocumentType</a></code>(
 <var title="">qualifiedName</var>, <var title="">publicId</var>, <var title="">systemId</var> )

 <dd>
  <p>Returns a <a href="#concept-doctype" title="concept-doctype">doctype</a>, with the given
  <var title="">qualifiedName</var>, <var title="">publicId</var>, and
  <var title="">systemId</var>. If <var title="">qualifiedName</var> does not
  match the <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production, an
  "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>"
  exception is thrown, and if it does not match the
  <code class="external"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production, a
  "<code><a href="#namespaceerror">NamespaceError</a></code>" exception
  is thrown.


 <dt><var title="">doc</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-createDocument"><a href="#dom-domimplementation-createdocument">createDocument</a></code>( <var title="">namespace</var>, <var title="">qualifiedName</var>, <var title="">doctype</var> )

 <dd>
  <p>Returns an <code><a href="#xmldocument">XMLDocument</a></code>, with a
  <a href="#document-element">document element</a> whose
  <a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is
  <var title="">qualifiedName</var> and whose
  <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> is
  <var title="">namespace</var> (unless <var title="">qualifiedName</var> is the
  empty string), and with <var title="">doctype</var>, if it is given, as its
  <a href="#concept-doctype" title="concept-doctype">doctype</a>.

  <p>This method throws the same exceptions as the <code title="dom-Document-createElementNS"><a href="#dom-document-createelementns">createElementNS</a></code> method, when
  invoked with the same arguments.


 <dt><var title="">doc</var> = <var title="">document</var> . <code title="dom-Document-implementation"><a href="#dom-document-implementation">implementation</a></code> . <code title="dom-DOMImplementation-createHTMLDocument"><a href="#dom-domimplementation-createhtmldocument">createHTMLDocument</a></code>(
 <var title="">title</var> )

 <dd>
  <p>Returns a <a href="#concept-document" title="concept-document">document</a>, with a basic
  <a href="#concept-tree" title="concept-tree">tree</a> already constructed including a
  <code title="">title</code> element.
</dl>

<div class="impl">

<p>The
<dfn id="dom-domimplementation-createdocumenttype" title="dom-DOMImplementation-createDocumentType"><code>createDocumentType(<var>qualifiedName</var>, <var>publicId</var>, <var>systemId</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">qualifiedName</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.
 <li><p>If <var title="">qualifiedName</var> does not match the <code class="external"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production in,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.
 <!--<li><p>If <var title>publicId</var> contains a character that does not
 match the <code data-anolis-spec=xml>PubidChar</code> production in XML,
 <span title=concept-throw>throw</span> an
 "<code>InvalidCharacterError</code>"
 exception and terminate these steps. --> <!-- DOM3 didn't check this -->
 <!--<li><p>If <var title>systemId</var> contains both a U+0022 QUOTATION MARK ('"') and a U+0027 APOSTROPHE ("'") character,
 <span title=concept-throw>throw</span> an
 "<code>InvalidCharacterError</code>"
 exception and terminate these steps.--> <!-- DOM3 didn't check this -->
 <li><p>Return a new <a href="#concept-doctype" title="concept-doctype">doctype</a>, with
 <var title="">qualifiedName</var> as its
 <a href="#concept-doctype-name" title="concept-doctype-name">name</a>, <var title="">publicId</var> as
 its <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>, and
 <var title="">systemId</var> as its
 <a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>, and with its
 <a href="#concept-node-document" title="concept-node-document">node document</a> set to the
 associated <a href="#concept-document" title="concept-document">document</a> of the
 <a href="#context-object">context object</a>.
</ol>
<p class="note">No check is performed that the <var title="">publicId</var>
matches the <code title="">PublicChar</code> or that the
<var title="">systemId</var> does not contain both a '<code title="">"</code>' and
"<code title="">'</code>".

<p>The
<dfn id="dom-domimplementation-createdocument" title="dom-DOMImplementation-createDocument"><code>createDocument(<var>namespace</var>, <var>qualifiedName</var>, <var>doctype</var>)</code></dfn>
method must run these steps:

<ol>
 <li>
  <p>Let <var title="">document</var> be a new <code><a href="#xmldocument">XMLDocument</a></code>.

  <p class="note">This method creates an <code><a href="#xmldocument">XMLDocument</a></code> rather than
  a normal <a href="#concept-document" title="concept-document">document</a>. They are identical
  except for the addition of the
  <code class="external" title="dom-XMLDocument-load"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-xmldocument-load">load()</a></code>
  method deployed content relies upon.
  <a class="informative" href="#refsHTML">[HTML]</a>

 <li><p>Let <var title="">element</var> be null.

 <li><p>If <var title="">qualifiedName</var> is not the empty string, set
 <var title="">element</var> to the result of invoking the
 <code title="dom-Document-createElementNS"><a href="#dom-document-createelementns">createElementNS()</a></code> method
 with the arguments <var title="">namespace</var> and
 <var title="">qualifiedName</var> on <var title="">document</var>. If that threw
 an exception, re-throw the exception and terminate these steps.

 <li><p>If <var title="">doctype</var> is not null,
 <a href="#concept-node-append" title="concept-node-append">append</a>
 <var title="">doctype</var> to <var title="">document</var>.

 <li><p>If <var title="">element</var> is not null,
 <a href="#concept-node-append" title="concept-node-append">append</a>
 <var title="">element</var> to <var title="">document</var>.

 <li><p>Return <var title="">document</var>.
</ol>

<p>The
<dfn id="dom-domimplementation-createhtmldocument" title="dom-DOMImplementation-createHTMLDocument"><code>createHTMLDocument(<var>title</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>Let <var title="">doc</var> be a newly created
 <a href="#concept-document" title="concept-document">document</a>.

 <li><p>Mark <var title="">doc</var> as being an <a href="#html-document">HTML document</a>.

 <li><p>Set <var title="">doc</var>'s
 <a href="#concept-document-content-type" title="concept-document-content-type">content type</a> to
 "<code title="">text/html</code>".

 <li><p>Create a <a href="#concept-doctype" title="concept-doctype">doctype</a>, with
 "<code title="">html</code>"
 as its <a href="#concept-doctype-name" title="concept-doctype-name">name</a> and with its
 <a href="#concept-node-document" title="concept-node-document">node document</a> set to
 <var title="">doc</var>. <a href="#concept-node-append" title="concept-node-append">Append</a>
 the newly created node to <var title="">doc</var>.

 <li><p>Create an <code title="">html</code> element in the <a href="#html-namespace">HTML
 namespace</a>, and <a href="#concept-node-append" title="concept-node-append">append</a>
 it to <var title="">doc</var>.

 <li><p>Create a <code title="">head</code> element in the <a href="#html-namespace">HTML
 namespace</a>, and  <a href="#concept-node-append" title="concept-node-append">append</a>
 it to the <code title="">html</code> element created in the previous step.

 <li><p>Create a <code title="">title</code> element in the <a href="#html-namespace">HTML
 namespace</a>, and  <a href="#concept-node-append" title="concept-node-append">append</a>
 it to the <code title="">head</code> element created in the previous step.

 <li><p>Create a <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>, set
 its <a href="#concept-cd-data" title="concept-CD-data">data</a> to <var title="">title</var>
 (which could be the empty string), and
 <a href="#concept-node-append" title="concept-node-append">append</a> it to the
 <code title="">title</code> element created in the previous step.

 <li><p>Create a <code title="">body</code> element in the
 <a href="#html-namespace">HTML namespace</a>, and
 <a href="#concept-node-append" title="concept-node-append">append</a> it to the
 <code title="">html</code> element created in the earlier step.

 <li><p>Return <var title="">doc</var>.
</ol>

</div>



<h3 id="interface-documentfragment"><span class="secno">5.4 </span>Interface <code><a href="#documentfragment">DocumentFragment</a></code></h3>
<pre class="idl">interface <dfn id="documentfragment">DocumentFragment</dfn> : <a href="#node">Node</a> {
  // NEW
  void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
};</pre>



<h3 id="interface-documenttype"><span class="secno">5.5 </span>Interface <code><a href="#documenttype">DocumentType</a></code></h3>
<pre class="idl">interface <dfn id="documenttype">DocumentType</dfn> : <a href="#node">Node</a> {
  readonly attribute DOMString <a href="#dom-documenttype-name" title="dom-DocumentType-name">name</a>;
  readonly attribute DOMString <a href="#dom-documenttype-publicid" title="dom-DocumentType-publicId">publicId</a>;
  readonly attribute DOMString <a href="#dom-documenttype-systemid" title="dom-DocumentType-systemId">systemId</a>;<!--
  readonly attribute DOMString internalSubset;-->

  // NEW
  void <a href="#dom-childnode-before" title="dom-ChildNode-before">before</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-after" title="dom-ChildNode-after">after</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-replace" title="dom-ChildNode-replace">replace</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-remove" title="dom-ChildNode-remove">remove</a>();
};</pre>

<p><code><a href="#documenttype">DocumentType</a></code> <a href="#concept-node" title="concept-node">nodes</a> are
simply known as <dfn id="concept-doctype" title="concept-doctype">doctypes</dfn>.

<p><a href="#concept-doctype" title="concept-doctype">Doctypes</a> have an associated
<dfn id="concept-doctype-name" title="concept-doctype-name">name</dfn>,
<dfn id="concept-doctype-publicid" title="concept-doctype-publicid">public ID</dfn>, and
<dfn id="concept-doctype-systemid" title="concept-doctype-systemid">system ID</dfn>.

<p>When a <a href="#concept-doctype" title="concept-doctype">doctype</a> is created, its
<a href="#concept-doctype-name" title="concept-doctype-name">name</a> is always given. Unless
explicitly given when a <a href="#concept-doctype" title="concept-doctype">doctype</a> is
created, its <a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a> and
<a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a> are the empty string.

<p>The <dfn id="dom-documenttype-name" title="dom-DocumentType-name"><code>name</code></dfn> attribute
must return the <a href="#concept-doctype-name" title="concept-doctype-name">name</a>.

<p>The <dfn id="dom-documenttype-publicid" title="dom-DocumentType-publicId"><code>publicId</code></dfn>
attribute must return the
<a href="#concept-doctype-publicid" title="concept-doctype-publicid">public ID</a>.

<p>The <dfn id="dom-documenttype-systemid" title="dom-DocumentType-systemId"><code>systemId</code></dfn>
attribute must return the
<a href="#concept-doctype-systemid" title="concept-doctype-systemid">system ID</a>.



<!-- AttrExodus
<h3>Interface <code>Attr</code></h3>

<p>The tentative plan is to let <code>Attr</code> no longer have
child nodes and turn it into a very lightweight object that no longer
inherits from <code>Node</code> &mdash;
<a href=http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html>http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html</a>

<pre class=idl>interface <dfn>Attr</dfn> : <span>Node</span> {
  readonly attribute DOMString <span title=dom-Attr-name>name</span>;
  readonly attribute boolean <span title=dom-Attr-specified>specified</span>;
           attribute DOMString <span title=dom-Attr-value>value</span>;
  readonly attribute <span>Element</span> <span title=dom-Attr-ownerElement>ownerElement</span>;<!- -
  readonly attribute boolean isId;- ->
};</pre>

<p><code>Attr</code> nodes represent <dfn
title=concept-attribute>attributes</dfn>. They have a <dfn
title=concept-attribute-name>name</dfn> and an <dfn
title=concept-attribute-element>element</dfn> associated with them when they are
created<!- -, or when they are passed as the argument to the <code
title=dom-Element-setAttributeNode>setAttributeNode</code> method.
[createAttribute]- ->. <code>Attr</code> nodes are not considered part of the
document tree, so their <code title=dom-Node-parentNode>parentNode</code>, <code
title=dom-Node-previousSibling>previousSibling</code> and <code
title=dom-Node-nextSibling>nextSibling</code> attributes return null. Also, its
child nodes can not be manipulated directly through the <code
title=dom-Node-insertBefore>insertBefore</code>, <code
title=dom-Node-replaceChild>replaceChild</code> and <code
title=dom-Node-appendChild>appendChild</code> methods.

<p>The <dfn title=dom-Attr-name><code>name</code></dfn> attribute must return
the <span title=concept-attribute-name>name</span> associated with the
<span>context object</span>.

<p>The <dfn title=dom-Attr-specified><code>specified</code></dfn> attribute must
return true.

<p>The <dfn title=dom-Attr-value><code>value</code></dfn> attribute must return the value of the <span>context object</span>'s
<code title=dom-Node-textContent>textContent</code> attribute and on
setting, must set the <span>context object</span>'s
<code title=dom-Node-textContent>textContent</code> attribute to the new
value.

<p>The <dfn title=dom-Attr-ownerElement><code>ownerElement</code></dfn>
attribute must return the <span title=concept-attribute-element>element</span>
associated with the <span>context object</span><!- -, if there is one, or null
otherwise [createAttribute]- ->.
-->


<h3 id="interface-element"><span class="secno">5.6 </span>Interface <code><a href="#element">Element</a></code></h3>
<pre class="idl">interface <dfn id="element">Element</dfn> : <a href="#node">Node</a> {
  readonly attribute DOMString? <a href="#dom-element-namespaceuri" title="dom-Element-namespaceURI">namespaceURI</a>;
  readonly attribute DOMString? <a href="#dom-element-prefix" title="dom-Element-prefix">prefix</a>;
  readonly attribute DOMString <a href="#dom-element-localname" title="dom-Element-localName">localName</a>;
  readonly attribute DOMString <a href="#dom-element-tagname" title="dom-Element-tagName">tagName</a>;

           attribute DOMString <a href="#dom-element-id" title="dom-Element-id">id</a>;
           attribute DOMString <a href="#dom-element-classname" title="dom-Element-className">className</a>;
  readonly attribute <a href="#domtokenlist">DOMTokenList</a> <a href="#dom-element-classlist" title="dom-Element-classList">classList</a>;

  readonly attribute <a href="#attr">Attr</a>[] <a href="#dom-element-attributes" title="dom-Element-attributes">attributes</a>;
  DOMString? <a href="#dom-element-getattribute" title="dom-Element-getAttribute">getAttribute</a>(DOMString <var title="">name</var>);
  DOMString? <a href="#dom-element-getattributens" title="dom-Element-getAttributeNS">getAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  void <a href="#dom-element-setattribute" title="dom-Element-setAttribute">setAttribute</a>(DOMString <var title="">name</var>, DOMString <var title="">value</var>);
  void <a href="#dom-element-setattributens" title="dom-Element-setAttributeNS">setAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">name</var>, DOMString <var title="">value</var>);
  void <a href="#dom-element-removeattribute" title="dom-Element-removeAttribute">removeAttribute</a>(DOMString <var title="">name</var>);
  void <a href="#dom-element-removeattributens" title="dom-Element-removeAttributeNS">removeAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  boolean <a href="#dom-element-hasattribute" title="dom-Element-hasAttribute">hasAttribute</a>(DOMString <var title="">name</var>);
  boolean <a href="#dom-element-hasattributens" title="dom-Element-hasAttributeNS">hasAttributeNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
<!--
  <span>Attr</span> <span title=dom-Element-getAttributeNode>getAttributeNode</span>(DOMString name);
  <span>Attr</span> <span title=dom-Element-getAttributeNodeNS>getAttributeNodeNS</span>(DOMString namespace, DOMString localName);
  <span>Attr</span> <span title=dom-Element-setAttributeNode>setAttributeNode</span>(Attr newAttr);
  <span>Attr</span> <span title=dom-Element-removeAttributeNode>removeAttributeNode</span>(Attr oldAttr);
-->
  <a href="#nodelist">NodeList</a> <a href="#dom-element-getelementsbytagname" title="dom-Element-getElementsByTagName">getElementsByTagName</a>(DOMString <var title="">qualifiedName</var>);
  <a href="#nodelist">NodeList</a> <a href="#dom-element-getelementsbytagnamens" title="dom-Element-getElementsByTagNameNS">getElementsByTagNameNS</a>(DOMString? <var title="">namespace</var>, DOMString <var title="">localName</var>);
  <a href="#nodelist">NodeList</a> <a href="#dom-element-getelementsbyclassname" title="dom-Element-getElementsByClassName">getElementsByClassName</a>(DOMString <var title="">classNames</var>);

  readonly attribute <a href="#htmlcollection">HTMLCollection</a> <a href="#dom-element-children" title="dom-Element-children">children</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-element-firstelementchild" title="dom-Element-firstElementChild">firstElementChild</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-element-lastelementchild" title="dom-Element-lastElementChild">lastElementChild</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-element-previouselementsibling" title="dom-Element-previousElementSibling">previousElementSibling</a>;
  readonly attribute <a href="#element">Element</a>? <a href="#dom-element-nextelementsibling" title="dom-Element-nextElementSibling">nextElementSibling</a>;
  readonly attribute unsigned long <a href="#dom-element-childelementcount" title="dom-Element-childElementCount">childElementCount</a>;<!-- XXX remove??-->

  // NEW
  void <a href="#dom-rootnode-prepend" title="dom-RootNode-prepend">prepend</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-rootnode-append" title="dom-RootNode-append">append</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-before" title="dom-ChildNode-before">before</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-after" title="dom-ChildNode-after">after</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-replace" title="dom-ChildNode-replace">replace</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-remove" title="dom-ChildNode-remove">remove</a>();
};</pre>

<p><code><a href="#element">Element</a></code> <a href="#concept-node" title="concept-node">nodes</a> are simply
known as <dfn id="concept-element" title="concept-element">elements</dfn>.</p>

<p><a href="#concept-element" title="concept-element">Elements</a> have an associated
<dfn id="concept-element-namespace" title="concept-element-namespace">namespace</dfn>,
<dfn id="concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</dfn>, and
<dfn id="concept-element-local-name" title="concept-element-local-name">local name</dfn>. When an
<a href="#concept-element" title="concept-element">element</a> is created, its
<a href="#concept-element-local-name" title="concept-element-local-name">local name</a> is always given.
Unless explicitly given when an <a href="#concept-element" title="concept-element">element</a>
is created, its <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a> and
<a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> are
null.

<p><a href="#concept-element" title="concept-element">Elements</a> also have an ordered
<dfn id="concept-element-attribute" title="concept-element-attribute">attribute list</dfn>. Unless
explicitly given when an <a href="#concept-element" title="concept-element">element</a> is
created, its
<a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> is empty. An
<a href="#concept-element" title="concept-element">element</a>
<dfn id="concept-element-attribute-has" title="concept-element-attribute-has">has</dfn> an
<a href="#concept-attribute" title="concept-attribute">attribute</a> <var title="">A</var> if
<var title="">A</var> is in its
<a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.

<p><a href="#concept-element" title="concept-element">Elements</a> can have a
<dfn id="concept-id" title="concept-id">unique identifier (ID)</dfn> and
<dfn id="concept-class" title="concept-class">classes</dfn> associated with them.

<p class="note">Historically <a href="#concept-element" title="concept-element">elements</a> could
have multiple identifiers e.g. by using the HTML <code title="">id</code>
<a href="#concept-attribute" title="concept-attribute">attribute</a> and a DTD. This specification
makes <a href="#concept-id" title="concept-id">ID</a> a concept of the DOM and allows for
only one per <a href="#concept-element" title="concept-element">element</a>, given by an
<code title="">id</code> <a href="#concept-attribute" title="concept-attribute">attribute</a>.

<p>An <a href="#concept-element" title="concept-element">element</a> has an
<a href="#concept-id" title="concept-id">ID</a> if it
<a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> an
<a href="#concept-named-attribute" title="concept-named-attribute"><code>id</code> attribute</a> whose
<a href="#concept-attribute-value" title="concept-attribute-value">value</a> is not the empty string.
The <a href="#concept-id" title="concept-id">ID</a> is that
<a href="#concept-attribute" title="concept-attribute">attribute</a>'s
<a href="#concept-attribute-value" title="concept-attribute-value">value</a>.

<p>An <a href="#concept-element" title="concept-element">element</a> has
<a href="#concept-class" title="concept-class">classes</a> if it
<a href="#concept-element-attribute-has" title="concept-element-attribute-has">has</a> a
<a href="#concept-named-attribute" title="concept-named-attribute"><code>class</code> attribute</a>, and
<a href="#split-a-string-on-spaces" title="split a string on spaces">splitting</a> that
<a href="#concept-attribute" title="concept-attribute">attribute</a>'s
<a href="#concept-attribute-value" title="concept-attribute-value">value</a> does not return an empty
list. The <a href="#concept-class" title="concept-class">classes</a> are that
<a href="#concept-attribute" title="concept-attribute">attribute</a>'s
<a href="#concept-attribute-value" title="concept-attribute-value">value</a>
<a href="#split-a-string-on-spaces" title="split a string on spaces">split on spaces</a>.

<p class="note">While this specification defines user agent processing
requirements for <code title="">id</code> and <code title="">class</code>
<a href="#concept-attribute" title="concept-attribute">attributes</a> on any
<a href="#concept-element" title="concept-element">element</a>, it makes no claims as to whether
using them is conforming or not.

<hr>

<p>A <a href="#concept-node" title="concept-node">node</a>'s
<a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of type
<code><a href="#element">Element</a></code> is known as a <dfn id="parent-element">parent element</dfn>. If the
<a href="#concept-node" title="concept-node">node</a> has a
<a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of a different type, its
<a href="#parent-element">parent element</a> is null.</p>

<p>The <dfn id="document-element">document element</dfn> of a
<a href="#concept-document" title="concept-document">document</a> is the
<a href="#concept-element" title="concept-element">element</a> whose
<a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is that
<a href="#concept-document" title="concept-document">document</a>, if it exists, and null otherwise.

<p class="note">As explained in the <a href="#node-tree">node tree</a> section,
there can only be one such <a href="#concept-element" title="concept-element">element</a>.

<p>When an <a href="#concept-element" title="concept-element">element</a> or one of its
<a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestors</a> is the
<a href="#document-element">document element</a>, it is <dfn id="in-a-document">in a document</dfn>.

<hr>

<p>Specifications may define <dfn id="base-url-change-steps">base URL change steps</dfn>.

<p>When an <a href="#concept-element" title="concept-element">element</a> is
<dfn id="affected-by-a-base-url-change">affected by a base URL change</dfn>, the user agent must run the
<a href="#base-url-change-steps">base URL change steps</a>, as defined in
<a href="#other-applicable-specifications">other applicable specifications</a>.

<hr>

<dl class="domintro">
 <dt><var title="">namespace</var> = <var title="">element</var> . <code title="dom-Element-namespaceURI"><a href="#dom-element-namespaceuri">namespaceURI</a></code>
 <dd><p>Returns the <a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>.

 <dt><var title="">prefix</var> = <var title="">element</var> . <code title="dom-Element-prefix"><a href="#dom-element-prefix">prefix</a></code>
 <dd><p>Returns the
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>.

 <dt><var title="">localName</var> = <var title="">element</var> . <code title="dom-Element-localName"><a href="#dom-element-localname">localName</a></code>
 <dd><p>Returns the
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.

 <dt><var title="">qualifiedName</var> = <var title="">element</var> . <code title="dom-Element-tagName"><a href="#dom-element-tagname">tagName</a></code>
 <dd><p>If
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
 null returns the concatenation of
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>,
 "<code title="">:</code>", and
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>. Otherwise it
 returns the <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.
 (The return value is uppercased in an <a href="#html-document">HTML document</a>.)
</dl>

<p>The <dfn id="dom-element-namespaceuri" title="dom-Element-namespaceURI"><code>namespaceURI</code></dfn>
attribute must return the <a href="#context-object">context object</a>'s
<a href="#concept-element-namespace" title="concept-element-namespace">namespace</a>.

<p>The <dfn id="dom-element-prefix" title="dom-Element-prefix"><code>prefix</code></dfn> attribute must return the <a href="#context-object">context object</a>'s
<a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>.

<p>The <dfn id="dom-element-localname" title="dom-Element-localName"><code>localName</code></dfn>
attribute must return the <a href="#context-object">context object</a>'s
<a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.

<p>The <dfn id="dom-element-tagname" title="dom-Element-tagName"><code>tagName</code></dfn> attribute
must run these steps:
<ol>
 <li><p>If <a href="#context-object">context object</a>'s
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a> is not
 null, let <var title="">qualified name</var> be its
 <a href="#concept-element-namespace-prefix" title="concept-element-namespace-prefix">namespace prefix</a>, followed
 by a "<code>:</code>" (U+003A), followed by its
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>. Otherwise, let
 <var title="">qualified name</var> be its
 <a href="#concept-element-local-name" title="concept-element-local-name">local name</a>.

 <li><p>If the <a href="#context-object">context object</a> is in the <a href="#html-namespace">HTML namespace</a> and
 its <a href="#concept-node-document" title="concept-node-document">node document</a> is an
 <a href="#html-document">HTML document</a>, let <var title="">qualified name</var> be
 <a href="#converted-to-ascii-uppercase">converted to ASCII uppercase</a>.

 <li><p>Return <var title="">qualified name</var>.
</ol>

<hr>

<!--
 XXX This section argues for generic get/set attribute algorithms; might
 need more text for DOMTokenList explaining various reflecting conditions.
-->

<p>Some IDL attributes are defined to
<dfn id="concept-reflect" title="concept-reflect">reflect</dfn> a particular content attribute.
This means that on getting, the following steps must be run:

<ol>
  <li>Let <var title="">value</var> be the result of invoking
  <code title="dom-Element-getAttribute"><a href="#dom-element-getattribute">getAttribute()</a></code> with the name
  of the content attribute as its argument.

  <li>If <var title="">value</var> is null, return the empty string and
  terminate these steps.

  <li>Return <var title="">value</var>.
</ol>

<p>On setting, the user agent must invoke
<code title="dom-Element-setAttribute"><a href="#dom-element-setattribute">setAttribute()</a></code> with the name of
the content attribute and the new value as its arguments.
<!-- XXX need to use namespace aware methods instead -->

<p>The <dfn id="dom-element-id" title="dom-Element-id"><code>id</code></dfn> attribute must
<a href="#concept-reflect" title="concept-reflect">reflect</a> the "<code title="">id</code>"
content attribute.

<p>The <dfn id="dom-element-classname" title="dom-Element-className"><code>className</code></dfn>
attribute must <a href="#concept-reflect" title="concept-reflect">reflect</a> the
"<code title="">class</code>" content attribute.

<p>The <dfn id="dom-element-classlist" title="dom-Element-classList"><code>classList</code></dfn>
attribute must return a <code><a href="#domtokenlist">DOMTokenList</a></code> whose
<a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> is
the <code title="dom-Element-className"><a href="#dom-element-classname">className</a></code> attribute value.

<hr>

<!-- all members in this subsection are affected by AttrExodus -->

<p>The <dfn id="dom-element-attributes" title="dom-Element-attributes"><code>attributes</code></dfn>
attribute must return a <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-read-only-array">read only array</a>
of the <a href="#context-object">context object</a>'s
<a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.
The returned <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-read-only-array">read only array</a> must be
live. I.e. changes to the associated
<a href="#concept-attribute" title="concept-attribute">attributes</a> are reflected.
<!-- XXXlive define live centrally somewhere for both collections and this? -->

<p>The <dfn id="dom-element-getattribute" title="dom-Element-getAttribute"><code>getAttribute(<var title="">name</var>)</code></dfn> method must run these steps:
<ol>
 <li><p>If the <a href="#context-object">context object</a> is in the
 <a href="#html-namespace">HTML namespace</a> and its
 <a href="#concept-node-document" title="concept-node-document">node document</a> is an
 <a href="#html-document">HTML document</a>, let <var title="">name</var> be
 <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.

 <li><p>Return the <a href="#concept-attribute-value" title="concept-attribute-value">value</a> of the
 first <a href="#concept-attribute" title="concept-attribute">attribute</a> in the
 <a href="#context-object">context object</a>'s
 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var>, or null otherwise.
</ol>

<p>The
<dfn id="dom-element-getattributens" title="dom-Element-getAttributeNS"><code>getAttributeNS(<var title="">namespace</var>, <var title="">localName</var>)</code></dfn>
method must return the following steps:
<ol>
  <li><p>If <var title="">namespace</var> is the empty string, set it to null.

  <li><p>Return the <a href="#concept-attribute-value" title="concept-attribute-value">value</a> of the
  <a href="#concept-attribute" title="concept-attribute">attribute</a> in the
  <a href="#context-object">context object</a>'s
  <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> whose
  <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is
  <var title="">namespace</var> and
  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
  <var title="">localName</var>, if it has one, or null otherwise.
</ol>

<p>The
<dfn id="dom-element-setattribute" title="dom-Element-setAttribute"><code>setAttribute(<var title="">name</var>, <var title="">value</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">name</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production in XML,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><p>If the <a href="#context-object">context object</a> is in the <a href="#html-namespace">HTML namespace</a>
 and its <a href="#concept-node-document" title="concept-node-document">node document</a> is an
 <a href="#html-document">HTML document</a>, let <var title="">name</var> be
 <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.

 <!-- https://bugzilla.mozilla.org/show_bug.cgi?id=315805 -->
 <li><p>If "<code title="">xmlns</code>" is a <a href="#prefix-match">prefix match</a> for
 <var title="">name</var>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" and terminate these steps.

 <li><p>If the <a href="#context-object">context object</a> does not have an
 <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var>, create an
 <a href="#concept-attribute" title="concept-attribute">attribute</a>, whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var> and
 <a href="#concept-attribute-value" title="concept-attribute-value">value</a> is <var title="">value</var>,
 and then <a href="#concept-element-attributes-append" title="concept-element-attributes-append">append</a> this
 <a href="#concept-attribute" title="concept-attribute">attribute</a> to the
 <a href="#context-object">context object</a>.

 <li><p>Otherwise, <a href="#concept-attribute-change" title="concept-attribute-change">change</a> the
 first <a href="#concept-attribute" title="concept-attribute">attribute</a> in the
 <a href="#context-object">context object</a>'s
 <a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a> whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var>, to <var title="">value</var>.
</ol>

<p>The
<dfn id="dom-element-setattributens" title="dom-Element-setAttributeNS"><code>setAttributeNS(<var title="">namespace</var>, <var title="">name</var>, <var title="">value</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <var title="">namespace</var> is the empty string, set it to null.

 <li><p>If <var title="">name</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml/#NT-Name">Name</a></code> production in XML,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><p>If <var title="">name</var> does not match the
 <code class="external"><a href="http://www.w3.org/TR/xml-names/#NT-QName">QName</a></code> production in Namespaces in XML,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">name</var> contains a "<code>:</code>" (U+003E),
 then split the string on it and let <var title="">prefix</var> be the part
 before and <var title="">localName</var> the part after. Otherwise, let
 <var title="">prefix</var> be null and <var title="">localName</var> be
 <var title="">name</var>.

 <li><p>If <var title="">prefix</var> is not null and
 <var title="">namespace</var> is null, <a href="#concept-throw" title="concept-throw">throw</a>
 a "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">prefix</var> is "<code title="">xml</code>" and
 <var title="">namespace</var> is not the <a href="#xml-namespace">XML namespace</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">name</var> or <var title="">prefix</var> is
 "<code title="">xmlns</code>" and <var title="">namespace</var> is not the
 <a href="#xmlns-namespace">XMLNS namespace</a>, <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">namespace</var> is the <a href="#xmlns-namespace">XMLNS namespace</a>
 and neither <var title="">name</var> nor <var title="">prefix</var> is
 "<code title="">xmlns</code>", <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#namespaceerror">NamespaceError</a></code>" exception and terminate these steps.

 <li><p>If the <a href="#context-object">context object</a> does not
 <a href="#concept-element-attribute-has" title="concept-element-attribute-has">have</a> an
 <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
 <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is
 <var title="">namespace</var> and
 <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
 <var title="">localName</var>, create an
 <a href="#concept-attribute" title="concept-attribute">attribute</a>, whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var>,
 <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is
 <var title="">namespace</var>,
 <a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> is
 <var title="">prefix</var>,
 <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
 <var title="">localName</var>, and <a href="#concept-attribute-value" title="concept-attribute-value">value</a>
 is <var title="">value</var>, and then
 <a href="#concept-element-attributes-append" title="concept-element-attributes-append">append</a> this
 <a href="#concept-attribute" title="concept-attribute">attribute</a> to the
 <a href="#context-object">context object</a>.

 <li><p>Otherwise, <a href="#concept-attribute-change" title="concept-attribute-change">change</a> that
 <a href="#concept-attribute" title="concept-attribute">attribute</a> to <var title="">value</var>.
</ol>

<p>The
<dfn id="dom-element-removeattribute" title="dom-Element-removeAttribute"><code>removeAttribute(<var>name</var>)</code></dfn>
method must run these steps:
<ol>
 <li><p>If the <a href="#context-object">context object</a> is in the
 <a href="#html-namespace">HTML namespace</a> and its
 <a href="#concept-node-document" title="concept-node-document">node document</a> is an
 <a href="#html-document">HTML document</a>, let <var title="">name</var> be
 <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.

 <li><p><a href="#concept-element-attributes-remove" title="concept-element-attributes-remove">Remove</a> the
 first <a href="#concept-attribute" title="concept-attribute">attribute</a> from the
 <a href="#context-object">context object</a> whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is <var title="">name</var>,
 if any.
</ol>

<p>The
<dfn id="dom-element-removeattributens" title="dom-Element-removeAttributeNS"><code>removeAttributeNS(<var>namespace</var>, <var>localName</var>)</code></dfn>
method must return the following steps:
<ol>
  <li><p>If <var title="">namespace</var> is the empty string, set it to null.

  <li><p><a href="#concept-element-attributes-remove" title="concept-element-attributes-remove">Remove</a> the
  <a href="#concept-attribute" title="concept-attribute">attribute</a> from the
  <a href="#context-object">context object</a> whose
  <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is
  <var title="">namespace</var> and
  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
  <var title="">localName</var>, if any.
</ol>

<p>The
<dfn id="dom-element-hasattribute" title="dom-Element-hasAttribute"><code>hasAttribute(<var>name</var>)</code></dfn>
method must run these steps:
<ol>
 <li><p>If the <a href="#context-object">context object</a> is in the
 <a href="#html-namespace">HTML namespace</a> and its
 <a href="#concept-node-document" title="concept-node-document">node document</a> is an
 <a href="#html-document">HTML document</a>, let <var title="">name</var> be
 <a href="#converted-to-ascii-lowercase">converted to ASCII lowercase</a>.

 <li><p>Return true if the <a href="#context-object">context object</a>
 <span title="concept-attribute-has">has</span> an
 <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
 <a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
 <var title="">name</var>, or false otherwise.
</ol>

<p>The
<dfn id="dom-element-hasattributens" title="dom-Element-hasAttributeNS"><code>hasAttributeNS(<var title="">namespace</var>, <var title="">localName</var>)</code></dfn>
method must return the following steps:
<ol>
  <li><p>If <var title="">namespace</var> is the empty string, set it to null.

  <li><p>Return true if the <a href="#context-object">context object</a>
  <span title="concept-attribute-has">has</span> an
  <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
  <a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> is
  <var title="">namespace</var> and
  <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
  <var title="">localName</var>, or false otherwise.
</ol>

<!--<dfn title=dom-Element-getAttributeNode>getAttributeNode</dfn>: when the
Element.getAttributeNode() method is invoked on an HTML element, the name
argument must be converted to ASCII lowercase before the element's attributes
are examined. (In HTML documents.) -->

<!-- <dfn title=dom-Element-setAttributeNode>setAttributeNode</dfn>: when an
Attr node is set on an HTML element using Element.setAttributeNode(), it must
have its name converted to ASCII lowercase before the element is affected.
(In HTML documents.) -->

<hr>

<p>When the
<dfn id="dom-element-getelementsbytagname" title="dom-Element-getElementsByTagName"><code>getElementsByTagName(<var>qualifiedName</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbytagname" title="concept-getElementsByTagName">list of elements with local name <var title="">localName</var></a>
for the <a href="#context-object">context object</a>.


<p>When the
<dfn id="dom-element-getelementsbytagnamens" title="dom-Element-getElementsByTagNameNS"><code>getElementsByTagNameNS(<var>namespace</var>, <var>localName</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbytagnamens" title="concept-getElementsByTagNameNS">list of elements with namespace <var title="">namespace</var> and local name <var title="">localName</var></a>
for the <a href="#context-object">context object</a>.


<p>When the
<dfn id="dom-element-getelementsbyclassname" title="dom-Element-getElementsByClassName"><code>getElementsByClassName(<var title="">classNames</var>)</code></dfn>
method must return the
<a href="#concept-getelementsbyclassname" title="concept-getElementsByClassName">list of elements with class names <var title="">classNames</var></a>
for the <a href="#context-object">context object</a>.

<hr>

<dl class="domintro">
 <dt><var title="">collection</var> = <var title="">element</var> . <code title="dom-Element-children"><a href="#dom-element-children">children</a></code>
 <dd><p>Returns the <a href="#concept-tree-child" title="concept-tree-child">child</a>
 <a href="#concept-element" title="concept-element">elements</a>.

 <dt><var title="">element</var> = <var title="">element</var> . <code title="dom-Element-firstElementChild"><a href="#dom-element-firstelementchild">firstElementChild</a></code>
 <dd><p>Returns the first <a href="#concept-tree-child" title="concept-tree-child">child</a> that
 is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.

 <dt><var title="">element</var> = <var title="">element</var> . <code title="dom-Element-lastElementChild"><a href="#dom-element-lastelementchild">lastElementChild</a></code>
 <dd><p>Returns the last <a href="#concept-tree-child" title="concept-tree-child">child</a> that
 is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.

 <dt><var title="">element</var> = <var title="">element</var> . <code title="dom-Element-previousElementSibling"><a href="#dom-element-previouselementsibling">previousElementSibling</a></code>
 <dd><p>Returns the first
 <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> that
 is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.

 <dt><var title="">element</var> = <var title="">element</var> . <code title="dom-Element-nextElementSibling"><a href="#dom-element-nextelementsibling">nextElementSibling</a></code>
 <dd><p>Returns the first
 <a href="#concept-tree-following" title="concept-tree-following">following</a>
 <a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> that
 is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.
</dl>

<p>The <dfn id="dom-element-children" title="dom-Element-children"><code>children</code></dfn> attribute
must return an <code><a href="#htmlcollection">HTMLCollection</a></code>
<a href="#concept-collection" title="concept-collection">collection</a> rooted at the
<a href="#context-object">context object</a> matching only
<a href="#concept-element" title="concept-element">element</a>
<a href="#concept-tree-child" title="concept-tree-child">children</a>.

<p>The
<dfn id="dom-element-firstelementchild" title="dom-Element-firstElementChild"><code>firstElementChild</code></dfn>
attribute must return the first <a href="#concept-tree-child" title="concept-tree-child">child</a>
that is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.

<p>The
<dfn id="dom-element-lastelementchild" title="dom-Element-lastElementChild"><code>lastElementChild</code></dfn>
attribute must return the last <a href="#concept-tree-child" title="concept-tree-child">child</a>
that is an <a href="#concept-element" title="concept-element">element</a>, or null otherwise.

<p>The
<dfn id="dom-element-previouselementsibling" title="dom-Element-previousElementSibling"><code>previousElementSibling</code></dfn>
attribute must return the first
<a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> that is an
<a href="#concept-element" title="concept-element">element</a>, or null otherwise.

<p>The
<dfn id="dom-element-nextelementsibling" title="dom-Element-nextElementSibling"><code>nextElementSibling</code></dfn>
attribute must return the first
<a href="#concept-tree-following" title="concept-tree-following">following</a>
<a href="#concept-tree-sibling" title="concept-tree-sibling">sibling</a> that is an
<a href="#concept-element" title="concept-element">element</a>, or null otherwise.


<p>The
<dfn id="dom-element-childelementcount" title="dom-Element-childElementCount"><code>childElementCount</code></dfn>
attribute must return the number of
<a href="#concept-tree-child" title="concept-tree-child">children</a> of the
<a href="#context-object">context object</a> that are
<a href="#concept-element" title="concept-element">elements</a>.
<!--
  XXX
  https://bugs.webkit.org/show_bug.cgi?id=65079
  https://bugzilla.mozilla.org/show_bug.cgi?id=673790
-->


<h4 id="interface-attr"><span class="secno">5.6.1 </span>Interface <code><a href="#attr">Attr</a></code></h4>
<pre class="idl">interface <dfn id="attr">Attr</dfn> {
  readonly attribute DOMString <a href="#dom-attr-name" title="dom-Attr-name">name</a>;
           attribute DOMString <a href="#dom-attr-value" title="dom-Attr-value">value</a>;

  readonly attribute DOMString? <a href="#dom-attr-namespaceuri" title="dom-Attr-namespaceURI">namespaceURI</a>;
  readonly attribute DOMString? <a href="#dom-attr-prefix" title="dom-Attr-prefix">prefix</a>;
  readonly attribute DOMString <a href="#dom-attr-localname" title="dom-Attr-localName">localName</a>;
};</pre>

<p><code><a href="#attr">Attr</a></code> objects are simply known as
<dfn id="concept-attribute" title="concept-attribute">attributes</dfn>.

<p><a href="#concept-attribute" title="concept-attribute">Attributes</a> have a
<dfn id="concept-attribute-name" title="concept-attribute-name">name</dfn> and
<dfn id="concept-attribute-value" title="concept-attribute-value">value</dfn>.

<p>For legacy reasons, <a href="#concept-attribute" title="concept-attribute">attributes</a> also
have an associated <dfn id="concept-attribute-namespace" title="concept-attribute-namespace">namespace</dfn>,
<dfn id="concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</dfn>, and
<dfn id="concept-attribute-local-name" title="concept-attribute-local-name">local name</dfn>.

<p>When an <a href="#concept-attribute" title="concept-attribute">attribute</a> is created, its
<a href="#concept-attribute-name" title="concept-attribute-name">name</a> and
<a href="#concept-attribute-value" title="concept-attribute-value">value</a> are always given. Unless
explicitly given when an <a href="#concept-attribute" title="concept-attribute">attribute</a> is
created, its <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a> is
identical to its <a href="#concept-attribute-name" title="concept-attribute-name">name</a>, and its
<a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> and
<a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> are
null.

<p>An
<dfn id="concept-named-attribute" title="concept-named-attribute"><code><var title="">A</var></code> attribute</dfn>
is an <a href="#concept-attribute" title="concept-attribute">attribute</a> whose
<a href="#concept-attribute-name" title="concept-attribute-name">name</a> is
<code><var title="">A</var></code> and whose
<a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a> and
<a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a> are
null.

<hr>

<p>To <dfn id="concept-attribute-change" title="concept-attribute-change">change</dfn> an
<a href="#concept-attribute" title="concept-attribute">attribute</a> <var title="">attribute</var> to
<var title="">value</var>, set the <var title="">attribute</var>'s
<a href="#concept-attribute-value" title="concept-attribute-value">value</a> to <var title="">value</var>.

<!-- XXX move append/remove to attribute list? -->
<p>To <dfn id="concept-element-attributes-append" title="concept-element-attributes-append">append</dfn> an
<a href="#concept-attribute" title="concept-attribute">attribute</a> <var title="">attribute</var> to
an <a href="#concept-element" title="concept-element">element</a> <var title="">element</var>,
append the <var title="">attribute</var> to the <var title="">element</var>'s
<a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.

<p>To <dfn id="concept-element-attributes-remove" title="concept-element-attributes-remove">remove</dfn> an
<a href="#concept-attribute" title="concept-attribute">attribute</a> <var title="">attribute</var>
from an <a href="#concept-element" title="concept-element">element</a> <var title="">element</var>,
remove the <var title="">attribute</var> from the <var title="">element</var>'s
<a href="#concept-element-attribute" title="concept-element-attribute">attribute list</a>.

<p class="XXX">These definitions will be expanded upon in due course for
mutations.

<hr>

<p>The <dfn id="dom-attr-name" title="dom-Attr-name"><code>name</code></dfn> attribute must
return the <a href="#concept-attribute-name" title="concept-attribute-name">name</a>.

<p>The <dfn id="dom-attr-value" title="dom-Attr-value"><code>value</code></dfn> attribute must
return the <a href="#concept-attribute-value" title="concept-attribute-value">value</a>.

<p>Setting the <code title="dom-Attr-value"><a href="#dom-attr-value">value</a></code> attribute must set
<a href="#concept-attribute-value" title="concept-attribute-value">value</a> to the new value.

<hr>

<p>The <dfn id="dom-attr-namespaceuri" title="dom-Attr-namespaceURI"><code>namespaceURI</code></dfn>
attribute must return the
<a href="#concept-attribute-namespace" title="concept-attribute-namespace">namespace</a>.

<p>The <dfn id="dom-attr-prefix" title="dom-Attr-prefix"><code>prefix</code></dfn> attribute must
return the
<a href="#concept-attribute-namespace-prefix" title="concept-attribute-namespace-prefix">namespace prefix</a>.

<p>The <dfn id="dom-attr-localname" title="dom-Attr-localName"><code>localName</code></dfn> attribute
must return the <a href="#concept-attribute-local-name" title="concept-attribute-local-name">local name</a>.


<h3 id="interface-characterdata"><span class="secno">5.7 </span>Interface <code><a href="#characterdata">CharacterData</a></code></h3>
<pre class="idl">interface <dfn id="characterdata">CharacterData</dfn> : <a href="#node">Node</a> {
  [TreatNullAs=EmptyString] attribute DOMString <a href="#dom-characterdata-data" title="dom-CharacterData-data">data</a>;
  readonly attribute unsigned long <a href="#dom-characterdata-length" title="dom-CharacterData-length">length</a>;
  DOMString <a href="#dom-characterdata-substringdata" title="dom-CharacterData-substringData">substringData</a>(unsigned long <var title="">offset</var>, unsigned long <var title="">count</var>);
  void <a href="#dom-characterdata-appenddata" title="dom-CharacterData-appendData">appendData</a>(DOMString <var title="">data</var>);
  void <a href="#dom-characterdata-insertdata" title="dom-CharacterData-insertData">insertData</a>(unsigned long <var title="">offset</var>, DOMString <var title="">data</var>);
  void <a href="#dom-characterdata-deletedata" title="dom-CharacterData-deleteData">deleteData</a>(unsigned long <var title="">offset</var>, unsigned long <var title="">count</var>);
  void <a href="#dom-characterdata-replacedata" title="dom-CharacterData-replaceData">replaceData</a>(unsigned long <var title="">offset</var>, unsigned long <var title="">count</var>, DOMString <var title="">data</var>);

  // NEW
  void <a href="#dom-childnode-before" title="dom-ChildNode-before">before</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-after" title="dom-ChildNode-after">after</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-replace" title="dom-ChildNode-replace">replace</a>((<a href="#node">Node</a> or DOMString)... <var title="">nodes</var>);
  void <a href="#dom-childnode-remove" title="dom-ChildNode-remove">remove</a>();
};</pre>

<p class="note"><code><a href="#characterdata">CharacterData</a></code> is an abstract interface and does
not exist as <a href="#concept-node" title="concept-node">node</a>. It is used by
<code><a href="#text">Text</a></code>, <code><a href="#comment">Comment</a></code>, and
<code><a href="#processinginstruction">ProcessingInstruction</a></code> <a href="#concept-node" title="concept-node">nodes</a>.

<p>Each <a href="#concept-node" title="concept-node">node</a> inheriting from the
<code><a href="#characterdata">CharacterData</a></code> interface has an associated mutable string
called <dfn id="concept-cd-data" title="concept-CD-data">data</dfn>.

<p>To <dfn id="concept-cd-replace" title="concept-CD-replace">replace data</dfn> of node
<var title="">node</var> with offset <var title="">offset</var>, count
<var title="">count</var>, and data <var title="">data</var>, run these steps:</p>

<ol>
 <li><p>Let <var title="">length</var> be the <var title="">node</var>'s
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value.

 <li><p>If <var title="">offset</var> is greater than <var title="">length</var>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">offset</var> plus <var title="">count</var> is greater
 than <var title="">length</var> let <var title="">count</var> be
 <var title="">length</var> minus <var title="">offset</var>.

 <li><p>Insert <var title="">data</var> into <var title="">node</var>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a> after <var title="">offset</var>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a>.

 <li><p>Let <var title="">delete offset</var> be <var title="">offset</var> plus
 the number of
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> in
 <var title="">data</var>.

 <li><p>Starting from <var title="">delete offset</var>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a>, remove
 <var title="">count</var>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> from
 <var title="">node</var>'s <a href="#concept-cd-data" title="concept-CD-data">data</a>.

 <!-- ranges -->
 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
 <var title="">node</var> and
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
 <var title="">offset</var> but less than or equal to <var title="">offset</var>
 plus <var title="">count</var>, set its
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> to
 <var title="">offset</var>.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
 <var title="">node</var> and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
 <var title="">offset</var> but less than or equal to <var title="">offset</var>
 plus <var title="">count</var>, set its
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> to
 <var title="">offset</var>.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
 <var title="">node</var> and
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
 <var title="">offset</var> plus <var title="">count</var>, increase its
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by the number of
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> in
 <var title="">data</var>, then decrease it by <var title="">count</var>.

 <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
 <var title="">node</var> and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
 <var title="">offset</var> plus <var title="">count</var>, increase its
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by the number of
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> in
 <var title="">data</var>, then decrease it by <var title="">count</var>.
</ol>
<!-- delete happens after insert for better cursor positioning with editing
http://www.w3.org/Bugs/Public/show_bug.cgi?id=13153 -->

<!-- If you set a node's data to a new value (e.g., using the data
attribute):

IE 9: Acts like the node was deleted and recreated, moves the boundary
points up to the parent
Firefox 4: Resets the offset to 0, always
Chrome 11 dev: Resets the offset to 0, except it does nothing if the new
data is the same as the old data
Opera 11: Sets a start offset to 0 and an end offset to the end of the
data, always

The spec originally followed WebKit, since it seemed to make the most sense.
Opera's approach of setting end offsets to the length of the new data
arguably makes more sense, but that's debatable, and it's greatly
outnumbered. However, after some feedback by bzbarsky that checking for
equality is expensive, I removed the special case and matched Firefox:

http://www.w3.org/Bugs/Public/show_bug.cgi?id=13250

Authors who want WebKit-like behavior can always use replaceData() instead.

XXX replaceData is the same as setting data these days -->


<p>To <dfn id="concept-cd-substring" title="concept-CD-substring">substring data</dfn> with node
<var title="">node</var>, offset <var title="">offset</var>, and count
<var title="">count</var>, run these steps:

<ol>
 <li><p>Let <var title="">length</var> be <var title="">node</var>'s
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value.

 <li><p>If <var title="">offset</var> is greater than <var title="">length</var>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">offset</var> plus <var title="">count</var> is
 greater than <var title="">length</var>, return a string whose value is the
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> from the
 <var title="">offset</var><sup>th</sup>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit">code unit</a> to the end of
 <var title="">node</var>'s <a href="#concept-cd-data" title="concept-CD-data">data</a>, and then
 terminate these steps.

 <li><p>Return a string whose value is the
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> from the
 <var title="">offset</var><sup>th</sup>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit">code unit</a> to the
 <var title="">offset</var>+<var title="">count</var><sup>th</sup>
 <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit">code unit</a> in <var title="">node</var>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a>.
</ol>

<p>The <dfn id="dom-characterdata-data" title="dom-CharacterData-data"><code>data</code></dfn> attribute
must return <a href="#concept-cd-data" title="concept-CD-data">data</a>, and on setting, must
<a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
<a href="#context-object">context object</a> offset 0, count
<code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, and data
new value.

<p>The <dfn id="dom-characterdata-length" title="dom-CharacterData-length"><code>length</code></dfn>
attribute must return the number of
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-code-unit" title="code unit">code units</a> in
<a href="#concept-cd-data" title="concept-CD-data">data</a>.

<p>The
<dfn id="dom-characterdata-substringdata" title="dom-CharacterData-substringData"><code>substringData(<var title="">offset</var>, <var title="">count</var>)</code></dfn>
method must <a href="#concept-cd-substring" title="concept-CD-substring">substring data</a> with node
<a href="#context-object">context object</a>, offset <var title="">offset</var>, and count
<var title="">count</var>.

<p>The
<dfn id="dom-characterdata-appenddata" title="dom-CharacterData-appendData"><code>appendData(<var title="">data</var>)</code></dfn>
method must <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
<a href="#context-object">context object</a>, offset
<code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value, count 0,
and data <var title="">data</var>.

<p>The
<dfn id="dom-characterdata-insertdata" title="dom-CharacterData-insertData"><code>insertData(<var title="">offset</var>, <var title="">data</var>)</code></dfn>
method must <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
<a href="#context-object">context object</a>, offset <var title="">offset</var>, count 0, and
data <var title="">data</var>.

<p>The
<dfn id="dom-characterdata-deletedata" title="dom-CharacterData-deleteData"><code>deleteData(<var title="">offset</var>, <var title="">count</var>)</code></dfn>
method must <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
<a href="#context-object">context object</a>, offset <var title="">offset</var>, count
<var title="">count</var>, and data the empty string.

<p>The
<dfn id="dom-characterdata-replacedata" title="dom-CharacterData-replaceData"><code>replaceData(<var title="">offset</var>, <var title="">count</var>, <var title="">data</var>)</code></dfn>
method must <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
<a href="#context-object">context object</a>, offset <var title="">offset</var>, count
<var title="">count</var>, and data <var title="">data</var>.


<h3 id="interface-text"><span class="secno">5.8 </span>Interface <code><a href="#text">Text</a></code></h3>
<pre class="idl">interface <dfn id="text">Text</dfn> : <a href="#characterdata">CharacterData</a> {
  <a href="#text">Text</a> <a href="#dom-text-splittext" title="dom-Text-splitText">splitText</a>(unsigned long <var title="">offset</var>);
  readonly attribute DOMString <a href="#dom-text-wholetext" title="dom-Text-wholeText">wholeText</a>;
};</pre>

<p>To <dfn id="concept-text-split" title="concept-Text-split">split</dfn> a <code><a href="#text">Text</a></code>
<a href="#concept-node" title="concept-node">node</a> <var title="">node</var> with offset
<var title="">offset</var>, run these steps:

<ol>
 <li><p>Let <var title="">length</var> be the
 <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute value.

 <li><p>If <var title="">offset</var> is greater than <var title="">length</var>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">count</var> be <var title="">length</var> minus
 <var title="">offset</var>.

 <li><p>Let <var title="">new data</var> be the result of
 <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
 <var title="">node</var>, offset <var title="">offset</var>, and count
 <var title="">count</var>.

 <li><p>Let <var title="">new node</var> be a new <code><a href="#text">Text</a></code>
 <a href="#concept-node" title="concept-node">node</a>, with the same
 <a href="#concept-node-document" title="concept-node-document">node document</a> as
 <var title="">node</var>. Set <var title="">new node</var>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a> to <var title="">new data</var>.

 <li><p>Let <var title="">parent</var> be the <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li>
  <p>If <var title="">parent</var> is not null, run these substeps:

  <ol>
   <li><p><a href="#concept-node-insert" title="concept-node-insert">Insert</a>
   <var title="">new node</var> into <var title="">parent</var> before
   <var title="">node</var>'s
   <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a>.
   <!-- Do this before we replace data, so that the data replacement won't
   mutate ranges prematurely:
   https://www.w3.org/Bugs/Public/show_bug.cgi?id=15325 -->

   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
   <var title="">node</var> and
   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater than
   <var title="">offset</var>, set its
   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> to
   <var title="">new node</var> and decrease its
   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> by
   <var title="">offset</var>.

   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
   <var title="">node</var> and
   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
   <var title="">offset</var>, set its
   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> to
   <var title="">new node</var> and decrease its
   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> by
   <var title="">offset</var>.
  </ol>

 <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
 <var title="">node</var>, offset <var title="">offset</var>, count
 <var title="">count</var>, and data the empty string.

 <li>
  <p>If <var title="">parent</var> is null, run these substeps:</p>

  <ol>
   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
   <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
   <var title="">node</var> and
   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> is greater
   than <var title="">offset</var>, set its
   <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> to
   <var title="">offset</var>.

   <li><p>For each <a href="#concept-range" title="concept-range">range</a> whose
   <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is
   <var title="">node</var> and
   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> is greater than
   <var title="">offset</var>, set its
   <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> to
   <var title="">offset</var>.
  </ol>

 <li><p>Return <var title="">new node</var>.
</ol>

<p>The
<dfn id="dom-text-splittext" title="dom-Text-splitText"><code>splitText(<var>offset</var>)</code></dfn>
method must <a href="#concept-text-split" title="concept-Text-split">split</a> the
<a href="#context-object">context object</a> with offset <var title="">offset</var>.


<p>The <dfn id="contiguous-text-nodes">contiguous <code>Text</code> nodes</dfn> of a node are the node
itself, the
<a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a>
<code><a href="#text">Text</a></code> node (if any) and its
<a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a>, and the
<a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a> <code><a href="#text">Text</a></code>
node (if any) and its <a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a>,
avoiding any duplicates.

<p>The <dfn id="dom-text-wholetext" title="dom-Text-wholeText"><code>wholeText</code></dfn>
attribute must return a concatenation of the
<a href="#concept-cd-data" title="concept-CD-data">data</a> of the
<a href="#contiguous-text-nodes">contiguous <code>Text</code> nodes</a> of the
<a href="#context-object">context object</a>, in
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>.



<h3 id="interface-processinginstruction"><span class="secno">5.9 </span>Interface <code><a href="#processinginstruction">ProcessingInstruction</a></code></h3>
<pre class="idl">interface <dfn id="processinginstruction">ProcessingInstruction</dfn> : <a href="#characterdata">CharacterData</a> {
  readonly attribute DOMString <a href="#dom-processinginstruction-target" title="dom-ProcessingInstruction-target">target</a>;
};</pre>

<p><code><a href="#processinginstruction">ProcessingInstruction</a></code> <a href="#concept-node" title="concept-node">nodes</a>
have an associated <dfn id="concept-pi-target" title="concept-PI-target">target</dfn>.

<p>The <dfn id="dom-processinginstruction-target" title="dom-ProcessingInstruction-target"><code>target</code></dfn>
attribute must return the <a href="#concept-pi-target" title="concept-PI-target">target</a>.



<h3 id="interface-comment"><span class="secno">5.10 </span>Interface <code><a href="#comment">Comment</a></code></h3>
<pre class="idl">interface <dfn id="comment">Comment</dfn> : <a href="#characterdata">CharacterData</a> {
};</pre>




<h2 id="ranges"><span class="secno">6 </span>Ranges</h2>

<!--
 TODO

 * setStart, setEnd, extractContents need to be concepts
 * ProcessingInstruction inheriting from CharacterData should allow for
   simplifications
 * make sure all methods do not call other methods but use concepts
-->


<!-- only needed by Ranges thus far -->
<p>The <dfn id="concept-node-length" title="concept-node-length">length</dfn> of a
<a href="#concept-node" title="concept-node">node</a> <var title="">node</var> depends on
<var title="">node</var>:
<dl class="switch">
 <dt><code><a href="#documenttype">DocumentType</a></code>
 <dd><p>0.

 <dt><code><a href="#text">Text</a></code>
 <dt><code><a href="#processinginstruction">ProcessingInstruction</a></code>
 <dt><code><a href="#comment">Comment</a></code>
 <dd><p>Its <code title="dom-CharacterData-length"><a href="#dom-characterdata-length">length</a></code> attribute
 value.

 <dt>Any other node
 <dd><p>Its number of <a href="#concept-tree-child" title="concept-tree-child">children</a>.
</dl>

<h3 id="interface-range"><span class="secno">6.1 </span>Interface <code><a href="#range">Range</a></code></h3>
<pre class="idl">interface <dfn id="range">Range</dfn> {
  readonly attribute <a href="#node">Node</a> <a href="#dom-range-startcontainer" title="dom-Range-startContainer">startContainer</a>;
  readonly attribute unsigned long <a href="#dom-range-startoffset" title="dom-Range-startOffset">startOffset</a>;
  readonly attribute <a href="#node">Node</a> <a href="#dom-range-endcontainer" title="dom-Range-endContainer">endContainer</a>;
  readonly attribute unsigned long <a href="#dom-range-endoffset" title="dom-Range-endOffset">endOffset</a>;
  readonly attribute boolean <a href="#dom-range-collapsed" title="dom-Range-collapsed">collapsed</a>;
  readonly attribute <a href="#node">Node</a> <a href="#dom-range-commonancestorcontainer" title="dom-Range-commonAncestorContainer">commonAncestorContainer</a>;

  void <a href="#dom-range-setstart" title="dom-Range-setStart">setStart</a>(<a href="#node">Node</a> <var title="">refNode</var>, unsigned long <var title="">offset</var>);
  void <a href="#dom-range-setend" title="dom-Range-setEnd">setEnd</a>(<a href="#node">Node</a> <var title="">refNode</var>, unsigned long <var title="">offset</var>);
  void <a href="#dom-range-setstartbefore" title="dom-Range-setStartBefore">setStartBefore</a>(<a href="#node">Node</a> <var title="">refNode</var>);
  void <a href="#dom-range-setstartafter" title="dom-Range-setStartAfter">setStartAfter</a>(<a href="#node">Node</a> <var title="">refNode</var>);
  void <a href="#dom-range-setendbefore" title="dom-Range-setEndBefore">setEndBefore</a>(<a href="#node">Node</a> <var title="">refNode</var>);
  void <a href="#dom-range-setendafter" title="dom-Range-setEndAfter">setEndAfter</a>(<a href="#node">Node</a> <var title="">refNode</var>);
  void <a href="#dom-range-collapse" title="dom-Range-collapse">collapse</a>(boolean <var title="">toStart</var>);
  void <a href="#dom-range-selectnode" title="dom-Range-selectNode">selectNode</a>(<a href="#node">Node</a> <var title="">refNode</var>);
  void <a href="#dom-range-selectnodecontents" title="dom-Range-selectNodeContents">selectNodeContents</a>(<a href="#node">Node</a> <var title="">refNode</var>);

  const unsigned short <dfn id="dom-comparehow-start_to_start" title="dom-CompareHow-START_TO_START">START_TO_START</dfn> = 0;
  const unsigned short <dfn id="dom-comparehow-start_to_end" title="dom-CompareHow-START_TO_END">START_TO_END</dfn> = 1;
  const unsigned short <dfn id="dom-comparehow-end_to_end" title="dom-CompareHow-END_TO_END">END_TO_END</dfn> = 2;
  const unsigned short <dfn id="dom-comparehow-end_to_start" title="dom-CompareHow-END_TO_START">END_TO_START</dfn> = 3;
  short <a href="#dom-range-compareboundarypoints" title="dom-Range-compareBoundaryPoints">compareBoundaryPoints</a>(unsigned short <var title="">how</var>, <a href="#range">Range</a> <var title="">sourceRange</var>);

  void <a href="#dom-range-deletecontents" title="dom-Range-deleteContents">deleteContents</a>();
  <a href="#documentfragment">DocumentFragment</a> <a href="#dom-range-extractcontents" title="dom-Range-extractContents">extractContents</a>();
  <a href="#documentfragment">DocumentFragment</a> <a href="#dom-range-clonecontents" title="dom-Range-cloneContents">cloneContents</a>();
  void <a href="#dom-range-insertnode" title="dom-Range-insertNode">insertNode</a>(<a href="#node">Node</a> <var title="">node</var>);
  void <a href="#dom-range-surroundcontents" title="dom-Range-surroundContents">surroundContents</a>(<a href="#node">Node</a> <var title="">newParent</var>);

  <a href="#range">Range</a> <a href="#dom-range-clonerange" title="dom-Range-cloneRange">cloneRange</a>();
  void <a href="#dom-range-detach" title="dom-Range-detach">detach</a>();

  boolean <a href="#dom-range-ispointinrange" title="dom-Range-isPointInRange">isPointInRange</a>(<a href="#node">Node</a> <var title="">node</var>, unsigned long <var title="">offset</var>);
  short <a href="#dom-range-comparepoint" title="dom-Range-comparePoint">comparePoint</a>(<a href="#node">Node</a> <var title="">node</var>, unsigned long <var title="">offset</var>);

  boolean <a href="#dom-range-intersectsnode" title="dom-Range-intersectsNode">intersectsNode</a>(<a href="#node">Node</a> <var title="">node</var>);

  <a href="#dom-range-stringifier" title="dom-Range-stringifier">stringifier</a>;
};</pre>

<p><code><a href="#range">Range</a></code> objects are simply known as
<dfn id="concept-range" title="concept-range">ranges</dfn>.

<p class="note"><a href="#concept-range" title="concept-range">Ranges</a> can be created using
the <code title="dom-Document-createRange"><a href="#dom-document-createrange">createRange()</a></code> method.

<p>A <dfn id="concept-range-bp" title="concept-range-bp">boundary point</dfn> is a
(<a href="#concept-node" title="concept-node">node</a>,
<dfn id="concept-range-bp-offset" title="concept-range-bp-offset">offset</dfn>) tuple, where
<a href="#concept-range-bp-offset" title="concept-range-bp-offset">offset</a> is a non-negative
integer.

<p class="note">Generally speaking, a
<a href="#concept-range-bp" title="concept-range-bp">boundary point</a>'s
<a href="#concept-range-bp-offset" title="concept-range-bp-offset">offset</a> will be between zero and
the <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>'s
<a href="#concept-node" title="concept-node">node</a>
<a href="#concept-node-length" title="concept-node-length">length</a>, inclusive. Algorithms that
modify a <a href="#concept-tree" title="concept-tree">tree</a> (in particular the
<a href="#concept-node-insert" title="concept-node-insert">insert</a>,
<a href="#concept-node-remove" title="concept-node-remove">remove</a>,
<a href="#concept-cd-replace" title="concept-CD-replace">replace data</a>, and
<a href="#concept-text-split" title="concept-Text-split">split</a> algorithms) also modify
<a href="#concept-range" title="concept-range">ranges</a> associated with that
<a href="#concept-tree" title="concept-tree">tree</a>.

<p>If the two <a href="#concept-node" title="concept-node">nodes</a> of
<a href="#concept-range-bp" title="concept-range-bp">boundary points</a>
(<var title="">node A</var>, <var title="">offset A</var>) and
(<var title="">node B</var>, <var title="">offset B</var>) have the same
<a href="#concept-tree-root" title="concept-tree-root">root</a>, the
<dfn id="concept-range-bp-position" title="concept-range-bp-position">position</dfn> of the first relative to
the second is either <dfn id="concept-range-bp-before" title="concept-range-bp-before">before</dfn>,
<dfn id="concept-range-bp-equal" title="concept-range-bp-equal">equal</dfn>, or
<dfn id="concept-range-bp-after" title="concept-range-bp-after">after</dfn>,
as returned by the following algorithm:

<ol>
 <li><p>If <var title="">node A</var> is the same as <var title="">node B</var>,
 return <a href="#concept-range-bp-equal" title="concept-range-bp-equal">equal</a> if
 <var title="">offset A</var> is the same as <var title="">offset B</var>,
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a> if
 <var title="">offset A</var> is less than <var title="">offset B</var>, and
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a> if
 <var title="">offset A</var> is greater than <var title="">offset B</var>.

 <li><p>If <var title="">node A</var> is
 <a href="#concept-tree-following" title="concept-tree-following">following</a>
 <var title="">node B</var>, compute the
 <a href="#concept-range-bp-position" title="concept-range-bp-position">position</a> of
 (<var title="">node B</var>, <var title="">offset B</var>) relative to
 (<var title="">node A</var>, <var title="">offset A</var>). If it is
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>, return
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>. If it is
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>, return
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>. In either case terminate
 these steps.

 <li>
  <p>If <var title="">node A</var> is an
  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of
  <var title="">node B</var>:

  <ol>
   <li><p>Let <var title="">child</var> equal <var title="">node B</var>.

   <li><p>While <var title="">child</var> is not a
   <a href="#concept-tree-child" title="concept-tree-child">child</a> of <var title="">node A</var>,
   set <var title="">child</var> to its
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

   <li><p>If the <a href="#concept-tree-index" title="concept-tree-index">index</a> of
   <var title="">child</var> is less than <var title="">offset A</var>, return
   <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>.
  </ol>

 <li><p>Return <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>.
</ol>

<p>Each <a href="#concept-range" title="concept-range">range</a> has two associated
<a href="#concept-range-bp" title="concept-range-bp">boundary points</a> &mdash; a
<dfn id="concept-range-start" title="concept-range-start">start</dfn> and
<dfn id="concept-range-end" title="concept-range-end">end</dfn> &mdash; an associated
<dfn id="concept-range-detached" title="concept-range-detached">detached flag</dfn>, which is initially
unset.

<p>For convenience, <dfn id="concept-range-start-node" title="concept-range-start-node">start node</dfn> is
<a href="#concept-range-start" title="concept-range-start">start</a>'s
<a href="#concept-node" title="concept-node">node</a>,
<dfn id="concept-range-start-offset" title="concept-range-start-offset">start offset</dfn> is
<a href="#concept-range-start" title="concept-range-start">start</a>'s
<a href="#concept-range-bp-offset" title="concept-range-bp-offset">offset</a>,
<dfn id="concept-range-end-node" title="concept-range-end-node">end node</dfn> is
<a href="#concept-range-end" title="concept-range-end">end</a>'s
<a href="#concept-node" title="concept-node">node</a>,  and
<dfn id="concept-range-end-offset" title="concept-range-end-offset">end offset</dfn> is
<a href="#concept-range-end" title="concept-range-end">end</a>'s
<a href="#concept-range-bp-offset" title="concept-range-bp-offset">offset</a>.

<p>The <dfn id="concept-range-root" title="concept-range-root">root</dfn> of a
<a href="#concept-range" title="concept-range">range</a> is the
<a href="#concept-tree-root" title="concept-tree-root">root</a> of its
<a href="#concept-range-start-node" title="concept-range-start-node">start node</a>, or null if its
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set.
<!-- start and end have an identical root -->

<p>A <a href="#concept-node" title="concept-node">node</a> <var title="">node</var> is
<dfn id="contained">contained</dfn> in a <a href="#concept-range" title="concept-range">range</a>
<var title="">range</var> if <var title="">node</var>'s
<a href="#concept-tree-root" title="concept-tree-root">root</a> is
the same as <var title="">range</var>'s
<a href="#concept-range-root" title="concept-range-root">root</a>, and (<var title="">node</var>, 0)
is <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a> <var title="">range</var>'s
<a href="#concept-range-start" title="concept-range-start">start</a>, and (<var title="">node</var>,
<a href="#concept-node-length" title="concept-node-length">length</a> of <var title="">node</var>) is
<a href="#concept-range-bp-before" title="concept-range-bp-before">before</a> <var title="">range</var>'s
<a href="#concept-range-end" title="concept-range-end">end</a>.

<p>A <a href="#concept-node" title="concept-node">node</a> is <dfn id="partially-contained">partially contained</dfn>
in a <a href="#concept-range" title="concept-range">range</a> if it is an
<a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of the
<a href="#concept-range" title="concept-range">range</a>'s
<a href="#concept-range-start-node" title="concept-range-start-node">start node</a> but not its
<a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, or vice versa.

<div class="note">
 <p>Some facts to better understand these definitions:

 <ul>
  <li><p>The content that one would think of as being within the
  <a href="#concept-range" title="concept-range">range</a> consists of all
  <a href="#contained">contained</a> <a href="#concept-node" title="concept-node">nodes</a>, plus
  possibly some of the contents of the
  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> and
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> if those are
  <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
  <a href="#concept-node" title="concept-node">nodes</a>.

  <li><p>The <a href="#concept-node" title="concept-node">nodes</a> that are contained in a
  <a href="#concept-range" title="concept-range">range</a> will generally not be contiguous,
  because the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of a
  <a href="#contained">contained</a> <a href="#concept-node" title="concept-node">node</a> will not
  always be <a href="#contained">contained</a>.

  <li><p>However, the <a href="#concept-tree-descendant" title="concept-tree-descendant">descendants</a>
  of a <a href="#contained">contained</a> <a href="#concept-node" title="concept-node">node</a> are
  <a href="#contained">contained</a>, and if two
  <a href="#concept-tree-sibling" title="concept-tree-sibling">siblings</a> are
  <a href="#contained">contained</a>, so are any
  <a href="#concept-tree-sibling" title="concept-tree-sibling">siblings</a> that lie between them.

  <li><p>The first <a href="#contained">contained</a>
  <a href="#concept-node" title="concept-node">node</a> (if there are any) will always be
  after the <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>, and the
  last <a href="#contained">contained</a> <a href="#concept-node" title="concept-node">node</a> will
  always be equal to or before the
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>'s last
  <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a>.

  <li><p>The <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> and
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> of a
  <a href="#concept-range" title="concept-range">range</a> are never <a href="#contained">contained</a>
  within it.

  <li><p>There exists some partially contained
  <a href="#concept-node" title="concept-node">node</a> if and only if the
  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> and
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> are different.

  <li><p>The
  <code title="dom-Range-commonAncestorContainer"><a href="#dom-range-commonancestorcontainer">commonAncestorContainer</a></code>
  attribute value is never <a href="#contained">contained</a> or
  <a href="#partially-contained">partially contained</a>.

  <li>If the <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is an
  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of the
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, the common
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> will
  be the <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>. Exactly one
  of its <a href="#concept-tree-child" title="concept-tree-child">children</a> will be
  <a href="#partially-contained">partially contained</a>, and a
  <a href="#concept-tree-child" title="concept-tree-child">child</a> will be <a href="#contained">contained</a>
  if and only if it <a href="#concept-tree-preceding" title="concept-tree-preceding">precedes</a> the
  <a href="#partially-contained">partially contained</a>
  <a href="#concept-tree-child" title="concept-tree-child">child</a>. If the
  <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is an
  <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of the
  <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>, the opposite
  holds.

  <li><p>If the <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is
  not an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  the <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, nor vice versa,
  the common
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> will
  be distinct from both of them. Exactly two of its
  <a href="#concept-tree-child" title="concept-tree-child">children</a> will be
  <a href="#partially-contained">partially contained</a>, and a
  <a href="#concept-tree-child" title="concept-tree-child">child</a> will be contained if and only
  if it lies between those two.
 </ul>
</div>

<hr>

<dl class="domintro">
 <dt><var title="">node</var> = <var title="">range</var> . <code title="dom-Range-startContainer"><a href="#dom-range-startcontainer">startContainer</a></code>
 <dd><p>Returns <var title="">range</var>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>.

 <dt><var title="">offset</var> = <var title="">range</var> . <code title="dom-Range-startOffset"><a href="#dom-range-startoffset">startOffset</a></code>
 <dd><p>Returns <var title="">range</var>'s
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>.

 <dt><var title="">node</var> = <var title="">range</var> . <code title="dom-Range-endContainer"><a href="#dom-range-endcontainer">endContainer</a></code>
 <dd><p>Returns <var title="">range</var>'s
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>.

 <dt><var title="">offset</var> = <var title="">range</var> . <code title="dom-Range-endOffset"><a href="#dom-range-endoffset">endOffset</a></code>
 <dd><p>Returns <var title="">range</var>'s
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>.

 <dt><var title="">collapsed</var> = <var title="">range</var> . <code title="dom-Range-collapsed"><a href="#dom-range-collapsed">collapsed</a></code>
 <dd><p>Returns true if <var title="">range</var>'s
 <a href="#concept-range-start" title="concept-range-start">start</a> and
 <a href="#concept-range-end" title="concept-range-end">end</a> are the same, or false otherwise.

 <dt><var title="">container</var> = <var title="">range</var> . <code title="dom-Range-commonAncestorContainer"><a href="#dom-range-commonancestorcontainer">commonAncestorContainer</a></code>
 <dd><p>Returns the <a href="#concept-node" title="concept-node">node</a>, furthest away from
 the <a href="#concept-document" title="concept-document">document</a>, that is an
 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of both
 <var title="">range</var>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> and
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>.
</dl>

<p>The <dfn id="dom-range-startcontainer" title="dom-Range-startContainer"><code>startContainer</code></dfn>
attribute must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set, or return
the <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> otherwise.

<p>The <dfn id="dom-range-startoffset" title="dom-Range-startOffset"><code>startOffset</code></dfn>
attribute must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set, or return
the <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> otherwise.

<p>The <dfn id="dom-range-endcontainer" title="dom-Range-endContainer"><code>endContainer</code></dfn>
attribute must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set, or return
the <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> otherwise.

<p>The <dfn id="dom-range-endoffset" title="dom-Range-endOffset"><code>endOffset</code></dfn>
attribute must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set, or return
the <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a> otherwise.

<p>The <dfn id="dom-range-collapsed" title="dom-Range-collapsed"><code>collapsed</code></dfn> attribute
must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set, return true
if <a href="#concept-range-start" title="concept-range-start">start</a> is the same as
<a href="#concept-range-end" title="concept-range-end">end</a>, or return false otherwise.

<p>The
<dfn id="dom-range-commonancestorcontainer" title="dom-Range-commonAncestorContainer"><code>commonAncestorContainer</code></dfn>
attribute must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">container</var> be
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>.

 <li><p>While <var title="">container</var> is not an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, let
 <var title="">container</var> be <var title="">container</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>Return <var title="">container</var>.
</ol>

<hr>

<p>To <dfn id="concept-range-bp-set" title="concept-range-bp-set">set the start or end</dfn> of a
<var title="">range</var> to a
<a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
(<var title="">node</var>, <var title="">offset</var>), run these steps:

<ol>
 <li><p>If <var title="">range</var>'s
 <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">node</var> is a
 <a href="#concept-doctype" title="concept-doctype">doctype</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.

 <li><p>If <var title="">offset</var> is greater than
 <var title="">node</var>'s <a href="#concept-node-length" title="concept-node-length">length</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">bp</var> be the
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">node</var>, <var title="">offset</var>).

 <li>
  <dl class="switch">
   <dt>If these steps were invoked as "set the start"
   <dd>
    <ol>
     <li><p>If <var title="">bp</var> is
     <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a> the
     <var title="">range</var>'s <a href="#concept-range-end" title="concept-range-end">end</a>, or
     if the <var title="">range</var>'s
     <a href="#concept-range-root" title="concept-range-root">root</a> is not equal to
     <var title="">node</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a>, set
     <var title="">range</var>'s <a href="#concept-range-end" title="concept-range-end">end</a> to
     <var title="">bp</var>.

     <li><p>Set <var title="">range</var>'s
     <a href="#concept-range-start" title="concept-range-start">start</a> to <var title="">bp</var>.
    </ol>
   <dt>If these steps were invoked as "set the end"
   <dd>
    <ol>
     <li><p>If <var title="">bp</var> is
     <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a> the
     <var title="">range</var>'s <a href="#concept-range-start" title="concept-range-start">start</a>,
     or if the <var title="">range</var>'s
     <a href="#concept-range-root" title="concept-range-root">root</a> is not equal to
     <var title="">node</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a>, set
     <var title="">range</var>'s <a href="#concept-range-start" title="concept-range-start">start</a>
     to <var title="">bp</var>.

     <li><p>Set <var title="">range</var>'s
     <a href="#concept-range-end" title="concept-range-end">end</a> to <var title="">bp</var>.
    </ol>
  </dl>
</ol>

<p>The
<dfn id="dom-range-setstart" title="dom-Range-setStart"><code>setStart(<var>node</var>, <var>offset</var>)</code></dfn>
method must <a href="#concept-range-bp-set" title="concept-range-bp-set">set the start</a> of the
<a href="#context-object">context object</a> to
<a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
(<var title="">node</var>, <var title="">offset</var>).

<p>The
<dfn id="dom-range-setend" title="dom-Range-setEnd"><code>setEnd(<var>refNode</var>, <var>offset</var>)</code></dfn>
method must <a href="#concept-range-bp-set" title="concept-range-bp-set">set the end</a> of the
<a href="#context-object">context object</a> to
<a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
(<var title="">node</var>, <var title="">offset</var>).

<p>The
<dfn id="dom-range-setstartbefore" title="dom-Range-setStartBefore"><code>setStartBefore(<var>node</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">parent</var> be <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.

 <li><p><a href="#concept-range-bp-set" title="concept-range-bp-set">Set the start</a> of the
 <a href="#context-object">context object</a> to
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a>).
</ol>

<p>The
<dfn id="dom-range-setstartafter" title="dom-Range-setStartAfter"><code>setStartAfter(<var>node</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">parent</var> be <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.

 <li><p><a href="#concept-range-bp-set" title="concept-range-bp-set">Set the start</a> of the
 <a href="#context-object">context object</a> to
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a> plus one).
</ol>

<p>The
<dfn id="dom-range-setendbefore" title="dom-Range-setEndBefore"><code>setEndBefore(<var>node</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">parent</var> be <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.

 <li><p><a href="#concept-range-bp-set" title="concept-range-bp-set">Set the end</a> of the
 <a href="#context-object">context object</a> to
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a>).
</ol>

<p>The
<dfn id="dom-range-setendafter" title="dom-Range-setEndAfter"><code>setEndAfter(<var>node</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">parent</var> be <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.

 <li><p><a href="#concept-range-bp-set" title="concept-range-bp-set">Set the end</a> of the
 <a href="#context-object">context object</a> to
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a> plus one).
</ol>


<p>The
<dfn id="dom-range-collapse" title="dom-Range-collapse"><code>collapse(<var>toStart</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">toStart</var> is true, set
 <a href="#concept-range-end" title="concept-range-end">end</a> to
 <a href="#concept-range-start" title="concept-range-start">start</a>. Otherwise, set
 <a href="#concept-range-start" title="concept-range-start">start</a> to
 <a href="#concept-range-end" title="concept-range-end">end</a>.
</ol>


<p>The
<dfn id="dom-range-selectnode" title="dom-Range-selectNode"><code>selectNode(<var>refNode</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">parent</var> be <var title="">refNode</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" and terminate these steps.

 <li><p>Let <var title="">index</var> be the
 <a href="#concept-tree-index" title="concept-tree-index">index</a> of <var title="">refNode</var>.

 <li><p>Set <a href="#concept-range-start" title="concept-range-start">start</a> to the
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">index</var>).

 <li><p>Set <a href="#concept-range-end" title="concept-range-end">end</a> to the
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">parent</var>, <var title="">index</var> plus one).
</ol>

<p>The
<dfn id="dom-range-selectnodecontents" title="dom-Range-selectNodeContents"><code>selectNodeContents(<var>refNode</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">refNode</var> is a
 <a href="#concept-doctype" title="concept-doctype">doctype</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" and terminate these steps.

 <li><p>Let <var title="">length</var> be the
 <a href="#concept-node-length" title="concept-node-length">length</a> of <var title="">refNode</var>.

 <li><p>Set <a href="#concept-range-start" title="concept-range-start">start</a> to the
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">refNode</var>, 0).

 <li><p>Set <a href="#concept-range-end" title="concept-range-end">end</a> to the
 <a href="#concept-range-bp" title="concept-range-bp">boundary point</a>
 (<var title="">refNode</var>, <var title="">length</var>).
</ol>

<hr>

<p>The
<dfn id="dom-range-compareboundarypoints" title="dom-Range-compareBoundaryPoints"><code>compareBoundaryPoints(<var>how</var>, <var>sourceRange</var>)</code></dfn>
method must run these steps:

<ol>
 <li><p>If <a href="#context-object">context object</a>'s or <var title="">sourceRange</var>'s
 <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li>
  <p>If <var>how</var> is not one of
  <ul>
   <li><code title="dom-CompareHow-START_TO_START"><a href="#dom-comparehow-start_to_start">START_TO_START</a></code>,
   <li><code title="dom-CompareHow-START_TO_END"><a href="#dom-comparehow-start_to_end">START_TO_END</a></code>,
   <li><code title="dom-CompareHow-END_TO_END"><a href="#dom-comparehow-end_to_end">END_TO_END</a></code>, and
   <li><code title="dom-CompareHow-END_TO_START"><a href="#dom-comparehow-end_to_start">END_TO_START</a></code>,
  </ul>
  <p><a href="#concept-throw" title="concept-throw">throw</a> a
  "<code><a href="#notsupportederror">NotSupportedError</a></code>" exception and terminate these steps.
 <!--
 Apparent behaviors from black-box testing:

 IE9: Converts to unsigned short per WebIDL, then throws "Error: Invalid
 argument." if it's not 0-3.

 Firefox 12.0a1: Converts to unsigned short per WebIDL, then throws
 NS_ERROR_ILLEGAL_VALUE if it's not 0-3.

 Chrome 17 dev: Converts to unsigned *long* per WebIDL, and treats bad values
 as 0.  Never throws.

 Opera Next 12.00 alpha: Throws NotSupportedError unless the value is -0, 0, 1,
 2, 3, or an integer equal to one of these modulo 2^32.  (In particular, it
 throws on NaN, Infinity, and -Infinity instead of treating them as 0 per
 WebIDL.)

 The spec follows IE9/Gecko, except that we throw NotSupportedError (like
 Opera) instead of a nonstandard exception type.
 -->

 <li><p>If <a href="#context-object">context object</a>'s
 <a href="#concept-range-root" title="concept-range-root">root</a> is not the same as
 <var title="">sourceRange</var>'s <a href="#concept-range-root" title="concept-range-root">root</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#wrongdocumenterror">WrongDocumentError</a></code>" exception and terminate these
 steps.

 <li>
  <p>If <var title="">how</var> is:
  <dl class="switch">
   <dt><code title="dom-CompareHow-START_TO_START"><a href="#dom-comparehow-start_to_start">START_TO_START</a></code>:
   <dd>
    <p>Let <var title="">this point</var> be the <a href="#context-object">context object</a>'s
    <a href="#concept-range-start" title="concept-range-start">start</a>.
    <p>Let <var title="">other point</var> be <var title="">sourceRange</var>'s
    <a href="#concept-range-start" title="concept-range-start">start</a>.

   <dt><code title="dom-CompareHow-START_TO_END"><a href="#dom-comparehow-start_to_end">START_TO_END</a></code>:
   <dd>
    <p>Let <var title="">this point</var> be the <a href="#context-object">context object</a>'s
    <a href="#concept-range-end" title="concept-range-end">end</a>.
    <p>Let <var title="">other point</var> be <var title="">sourceRange</var>'s
    <a href="#concept-range-start" title="concept-range-start">start</a>.

    <dt><code title="dom-CompareHow-END_TO_END"><a href="#dom-comparehow-end_to_end">END_TO_END</a></code>:
    <dd>
     <p>Let <var title="">this point</var> be the <a href="#context-object">context object</a>'s
     <a href="#concept-range-end" title="concept-range-end">end</a>.
     <p>Let <var title="">other point</var> be <var title="">sourceRange</var>'s
     <a href="#concept-range-end" title="concept-range-end">end</a>.

    <dt><code title="dom-CompareHow-END_TO_START"><a href="#dom-comparehow-end_to_start">END_TO_START</a></code>:
    <dd>
     <p>Let <var title="">this point</var> be the <a href="#context-object">context object</a>'s
     <a href="#concept-range-start" title="concept-range-start">start</a>.
     <p>Let <var title="">other point</var> be <var title="">sourceRange</var>'s
     <a href="#concept-range-end" title="concept-range-end">end</a>.
   </dl>

  <li>
   <p>If the <a href="#concept-range-bp-position" title="concept-range-bp-position">position</a> of
   <var title="">this point</var> relative to <var title="">other point</var> is

   <dl class="switch">
    <dt><a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>
    <dd>Return &minus;1.

    <dt><a href="#concept-range-bp-equal" title="concept-range-bp-equal">equal</a>
    <dd>Return 0.

    <dt><a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>
    <dd>Return 1.
   </dl>
</ol>

<p>The <dfn id="dom-range-deletecontents" title="dom-Range-deleteContents"><code>deleteContents()</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <a href="#concept-range-start" title="concept-range-start">start</a> equals
 <a href="#concept-range-end" title="concept-range-end">end</a>, terminate these steps.
 <!-- This might actually make no difference, but it's not immediately
 obvious what would happen otherwise if the start/end were text/comment:
 are all the substeps of the next step actually no-ops, or could some have
 side effects? -->

 <li><p>Let <var title="">original start node</var>,
 <var title="">original start offset</var>, <var title="">original end node</var>,
 and <var title="">original end offset</var> be the
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>,
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>,
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>, respectively.

 <li><p>If <var title="">original start node</var> and
 <var title="">original end node</var> are the same, and they are a
 <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
 <var title="">original start node</var>, offset
 <var title="">original start offset</var>, count
 <var title="">original end offset</var> minus
 <var title="">original start offset</var>, and data the empty string, and then
 terminate these steps.

 <li><p>Let <var title="">nodes to remove</var> be a list of all the
 <a href="#concept-node" title="concept-node">nodes</a> that are <a href="#contained">contained</a> in
 the <a href="#context-object">context object</a>, in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, omitting any
 <a href="#concept-node" title="concept-node">node</a> whose
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is also
 <a href="#contained">contained</a> in the <a href="#context-object">context object</a>.

 <li><p>If <var title="">original start node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, set
 <var title="">new node</var> to <var title="">original start node</var> and
 <var title="">new offset</var> to <var title="">original start offset</var>.

 <li>
  <p>Otherwise:
  <ol>
   <li><p>Let <var title="">reference node</var> equal
   <var title="">original start node</var>.

   <li><p>While <var title="">reference node</var>'s
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not null and is not an
   <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
   <var title="">original end node</var>, set <var title="">reference node</var>
   to its <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

   <li>
    <p>Set <var title="">new node</var> to the
    <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of
    <var title="">reference node</var>, and <var title="">new offset</var> to one
    plus the <a href="#concept-tree-index" title="concept-tree-index">index</a> of
    <var title="">reference node</var>.

    <p class="note">If <var title="">reference node</var>'s
    <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> were null, it would be the
    <a href="#concept-range-root" title="concept-range-root">root</a> of the
    <a href="#context-object">context object</a>, so would be an
    <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
    <var title="">original end node</var>, and we could not reach this point.
  </ol>

 <li><p>If <var title="">original start node</var> is a <code><a href="#text">Text</a></code> or
 <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
 <var title="">original start node</var>, offset
 <var title="">original start offset</var>, count
 <var title="">original start node</var>'s
 <a href="#concept-node-length" title="concept-node-length">length</a> minus
 <var title="">original start offset</var>, data the empty string.

 <li><p>For each <var title="">node</var> in <var title="">nodes to remove</var>,
 in <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, remove <var title="">node</var> from its <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.
 <!-- XXX use concept-node-remove? -->

 <li><p>If <var title="">original end node</var> is a <code><a href="#text">Text</a></code> or
 <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-cd-replace" title="concept-CD-replace">replace data</a> with node
 <var title="">original end node</var>, offset 0, count
 <var title="">original end offset</var>), and data the empty string.

 <li><p>Set <a href="#concept-range-start" title="concept-range-start">start</a> and
 <a href="#concept-range-end" title="concept-range-end">end</a> to
 (<var title="">new node</var>, <var title="">new offset</var>).
</ol>

<p>The <dfn id="dom-range-extractcontents" title="dom-Range-extractContents"><code>extractContents()</code></dfn> method
must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">frag</var> be a new <code><a href="#documentfragment">DocumentFragment</a></code>
 whose <a href="#concept-node-document" title="concept-node-document">node document</a> is the same as
 the <a href="#concept-node-document" title="concept-node-document">node document</a> of the
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>.

 <li><p>If <a href="#concept-range-start" title="concept-range-start">start</a> equals
 <a href="#concept-range-end" title="concept-range-end">end</a>, return <var title="">frag</var>, and
 terminate these steps.
 <!-- This is only really needed when the start and end nodes are
 text/comment, to avoid creating an empty clone as the child of the
 fragment. (Opera 11 actually does include such an empty clone, it seems,
 but Gecko and WebKit do not as of March 2011, so we follow them.)
 Otherwise, the following steps are all no-ops. But it's simplest to include
 this step anyway. -->

 <li><p>Let <var title="">original start node</var>,
 <var title="">original start offset</var>, <var title="">original end node</var>,
 and <var title="">original end offset</var> be the
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>,
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>,
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>, respectively.

 <li>
  <p>If <var title="">original start node</var> equals
  <var title="">original end node</var>, and they are a <code><a href="#text">Text</a></code> or
  <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original start node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, and count
   <var title="">original end offset</var> minus
   <var title="">original start offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

   <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, count
   <var title="">original end offset</var> minus
   <var title="">original start offset</var>, and data the empty string.

   <li><p>Return <var title="">frag</var> and terminate these steps.
  </ol>

 <li><p>Let <var title="">common ancestor</var> be
 <var title="">original start node</var>.

 <li><p>While <var title="">common ancestor</var> is not an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, set <var title="">common ancestor</var> to
 its own <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">original start node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, let
 <var title="">first partially contained child</var> be null.

 <li><p>Otherwise, let <var title="">first partially contained child</var> be
 the first <a href="#concept-tree-child" title="concept-tree-child">child</a> of
 <var title="">common ancestor</var> that is <a href="#partially-contained">partially contained</a>
 in the <a href="#context-object">context object</a>.

 <li><p>If <var title="">original end node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original start node</var>, let
 <var title="">last partially contained child</var> be null.

 <li>
  <p>Otherwise, let <var title="">last partially contained child</var> be
  the last <a href="#concept-tree-child" title="concept-tree-child">child</a> of
  <var title="">common ancestor</var> that is <a href="#partially-contained">partially contained</a>
  in the <a href="#context-object">context object</a>.

  <p class="note">These variable assignments do actually always make sense.
  For instance, if the original start node is not an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  the
  original end node, the original start node is itself partially contained in
  the range, and so are all its ancestors up until a child of the common
  ancestor. The common ancestor can't be original start node, because it must
  be an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  the original end node. The other case is
  similar. Also, notice that the two children will never be equal if both are
  defined.

 <li><p>Let <var title="">contained children</var> be a list of all
 <a href="#concept-tree-child" title="concept-tree-child">children</a> of
 <var title="">common ancestor</var> that are <a href="#contained">contained</a> in the
 <var title="">context object</var>, in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <li>
  <p>If any member of <var title="">contained children</var> is a
  <code><a href="#documenttype">DocumentType</a></code>, <a href="#concept-throw" title="concept-throw">throw</a> a
  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" exception and terminate these
  steps.
  <!-- Firefox 4.0 actually removes the non-DocumentType nodes before
  throwing the exception. Opera 11.00 removes the DocumentType too, and
  doesn't throw. I go with IE9 and Chrome 12 dev, which don't remove any
  nodes. DOM 2 Range doesn't specify what exactly happens here, except that
  an exception should be thrown. -->

  <p class="note">We do not have to worry about the first or last partially
  contained node, because a <code><a href="#documenttype">DocumentType</a></code> can never be
  partially contained. It cannot be a boundary point of a range, and it
  cannot be the ancestor of anything.

 <li><p>If <var title="">original start node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, set <var title="">new node</var> to
 <var title="">original start node</var> and <var title="">new offset</var> to
 <var title="">original start offset</var>.

 <li>
  <p>Otherwise:
  <ol>
    <li>Let <var title="">reference node</var> equal <var title="">original start
    node</var>.

    <li>While <var title="">reference node</var>'s <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is not null and is not an
    <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
    <var title="">original end node</var>,
    set <var title="">reference node</var> to its <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

    <li>Set <var title="">new node</var> to the <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of <var title="">reference node</var>,
    and <var title="">new offset</var> to one plus the <a href="#concept-tree-index" title="concept-tree-index">index</a> of <var title="">reference node</var>.

    <p class="note">If <var title="">reference node</var>'s <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> were null,
    it would be the <a href="#concept-range-root" title="concept-range-root">root</a> of the
    <a href="#context-object">context object</a>, so would be an
    <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of <var title="">original end node</var>, and we couldn't
    reach this point.
  </ol>

  <!-- Now we start with mutations, so we can't refer to the context object
  anymore unless we carefully consider how it will have mutated. -->

 <li>
  <p>If <var title="">first partially contained child</var> is a
  <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
  <a href="#concept-node" title="concept-node">node</a>:

  <p class="note">In this case, the first partially contained child is the
  original start node.

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original start node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, and count
   <var title="">original start node</var>'s
   <a href="#concept-node-length" title="concept-node-length">length</a> minus
   <var title="">original start offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

   <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, count
   <var title="">original start node</var>'s
   <a href="#concept-node-length" title="concept-node-length">length</a> minus
   <var title="">original start offset</var>, and data the empty string.
  </ol>

 <li>
  <p>Otherwise, if <var title="">first partially contained child</var> is not
  null:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">first partially contained child</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

    <li>Let <var title="">subrange</var> be a new <code><a href="#range">Range</a></code> whose <a href="#concept-range-start" title="concept-range-start">start</a> is (<var title="">original start
    node</var>, <var title="">original start offset</var>) and whose <a href="#concept-range-end" title="concept-range-end">end</a> is (<var title="">first partially contained
    child</var>, <a href="#concept-node-length" title="concept-node-length">length</a> of <var title="">first partially contained child</var>).

    <li>Let <var title="">subfrag</var> be the result of calling <code title="dom-Range-extractContents"><a href="#dom-range-extractcontents">extractContents()</a></code> on <var title="">subrange</var>.

    <p class="XXX">Is this method of recursing black-box detectable?  E.g., would
    it fire extra DOM mutation events or something?  What we really mean is to
    get a list of nodes to insert, then insert them directly into <var title="">frag</var>, without an intermediate document fragment.

   <li>For each <a href="#concept-tree-child" title="concept-tree-child">child</a> of
   <var title="">subfrag</var>, in
   <a href="#concept-tree-order" title="concept-tree-order">tree order</a>,
   <a href="#concept-node-append" title="concept-node-append">append</a> that
   <a href="#concept-tree-child" title="concept-tree-child">child</a> to <var title="">clone</var>.
  </ol>

 <li><p>For each <var title="">contained child</var> in
 <var title="">contained children</var>,
 <a href="#concept-node-append" title="concept-node-append">append</a>
 <var title="">contained child</var> to <var title="">frag</var>.

 <li>
  <p>If <var title="">last partially contained child</var> is a
  <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
  <a href="#concept-node" title="concept-node">node</a>:

  <p class="note">In this case, the last partially contained child is the
  original end node.

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original end node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original end node</var>, offset 0, and count
   <var title="">original end offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

    <li><p><a href="#concept-cd-replace" title="concept-CD-replace">Replace data</a> with node
    <var title="">original end node</var>, offset 0, count
    <var title="">original end offset</var>, and data the empty string.
  </ol>

 <li>
  <p>Otherwise, if <var title="">last partially contained child</var> is not
  null:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">last partially contained child</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

    <li>Let <var title="">subrange</var> be a new <code><a href="#range">Range</a></code> whose <a href="#concept-range-start" title="concept-range-start">start</a> is (<var title="">last partially
    contained child</var>, 0) and whose <a href="#concept-range-end" title="concept-range-end">end</a> is (<var title="">original end node</var>,
    <var title="">original end offset</var>).

    <li>Let <var title="">subfrag</var> be the result of calling <code title="dom-Range-extractContents"><a href="#dom-range-extractcontents">extractContents()</a></code> on <var title="">subrange</var>.

   <li><p>For each <a href="#concept-tree-child" title="concept-tree-child">child</a> of
   <var title="">subfrag</var>, in
   <a href="#concept-tree-order" title="concept-tree-order">tree order</a>,
   <a href="#concept-node-append" title="concept-node-append">append</a> that
   <a href="#concept-tree-child" title="concept-tree-child">child</a> to <var title="">clone</var>.
  </ol>

 <li><p>Set <a href="#concept-range-start" title="concept-range-start">start</a> and
 <a href="#concept-range-end" title="concept-range-end">end</a> to
 (<var title="">new node</var>, <var title="">new offset</var>).

 <li><p>Return <var title="">frag</var>.
</ol>

<p>The <dfn id="dom-range-clonecontents" title="dom-Range-cloneContents"><code>cloneContents()</code></dfn>
method must run these steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">frag</var> be a new <code><a href="#documentfragment">DocumentFragment</a></code>
 whose <a href="#concept-node-document" title="concept-node-document">node document</a> is the same as
 the <a href="#concept-node-document" title="concept-node-document">node document</a> of the
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>.

 <li><p>If <a href="#concept-range-start" title="concept-range-start">start</a> equals
 <a href="#concept-range-end" title="concept-range-end">end</a>, return <var title="">frag</var>, and
 terminate these steps.
 <!-- This is only really needed when the start and end nodes are
 text/comment, to avoid creating an empty clone as the child of the
 fragment. (Opera 11 actually does include such an empty clone, it seems,
 but Gecko and WebKit do not as of March 2011, so we follow them.)
 Otherwise, the following steps are all no-ops. But it's simplest to include
 this step anyway. -->

 <li><p>Let <var title="">original start node</var>,
 <var title="">original start offset</var>, <var title="">original end node</var>,
 and <var title="">original end offset</var> be the
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>,
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>,
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, and
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>, respectively.

 <li>
  <p>If <var title="">original start node</var> equals
  <var title="">original end node</var>, and they are a <code><a href="#text">Text</a></code> or
  <code><a href="#comment">Comment</a></code> <a href="#concept-node" title="concept-node">node</a>:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original start node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, and count
   <var title="">original end offset</var> minus
   <var title="">original start offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

   <li><p>Return <var title="">frag</var> and terminate these steps.
  </ol>

 <li><p>Let <var title="">common ancestor</var> be
 <var title="">original start node</var>.

 <li><p>While <var title="">common ancestor</var> is not an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, set
 <var title="">common ancestor</var> to its own
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">original start node</var> is an
 <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
 <var title="">original end node</var>, let
 <var title="">first partially contained child</var> be null.

 <li><p>Otherwise, let <var title="">first partially contained child</var> be
 the first <a href="#concept-tree-child" title="concept-tree-child">child</a> of
 <var title="">common ancestor</var> that is <a href="#partially-contained">partially contained</a>
 in the <a href="#context-object">context object</a>.

 <li><p>If <var title="">original end node</var> is an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  <var title="">original start node</var>, let <var title="">last
  partially contained child</var> be null.

  <li>Otherwise, let <var title="">last partially contained child</var> be the
  last <a href="#concept-tree-child" title="concept-tree-child">child</a> of
  <var title="">common ancestor</var> that is <a href="#partially-contained">partially contained</a> in
  the <a href="#context-object">context object</a>.

  <p class="note">These variable assignments do actually always make sense. For
  instance, if the original start node is not an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  the
  original end node, the original start node is itself partially contained in
  the range, and so are all its ancestors up until a child of the common
  ancestor. The common ancestor can't be original start node, because it must
  be an
  <a href="#concept-tree-inclusive-ancestor" title="concept-tree-inclusive-ancestor">inclusive ancestor</a> of
  the original end node. The other case is
  similar. Also, notice that the two children will never be equal if both are
  defined.

 <li><p>Let <var title="">contained children</var> be a list of all
 <a href="#concept-tree-child" title="concept-tree-child">children</a> of
 <var title="">common ancestor</var> that are <a href="#contained">contained</a> in the
 <var title="">context object</var>, in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <li>
  <p>If any member of <var title="">contained children</var> is a
  <code><a href="#documenttype">DocumentType</a></code>, <a href="#concept-throw" title="concept-throw">throw</a> a
  "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>" exception and terminate these
  steps.

  <p class="note">We don't have to worry about the first or last partially
  contained node, because a <code><a href="#documenttype">DocumentType</a></code> can never be partially
  contained. It can't be a boundary point of a range, and it can't be the
  ancestor of anything.

 <li>
  <p>If <var title="">first partially contained child</var> is a
  <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
  <a href="#concept-node" title="concept-node">node</a>:

  <p class="note">In this case, the first partially contained child is the
  original start node.

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original start node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original start node</var>, offset
   <var title="">original start offset</var>, and count
   <var title="">original start node</var>'s
   <a href="#concept-node-length" title="concept-node-length">length</a> minus
   <var title="">original start offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.
  </ol>

 <li>
  <p>Otherwise, if <var title="">first partially contained child</var> is not
  null:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">first partially contained child</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

    <li>Let <var title="">subrange</var> be a new <code><a href="#range">Range</a></code> whose <a href="#concept-range-start" title="concept-range-start">start</a> is (<var title="">original start
    node</var>, <var title="">original start offset</var>) and whose <a href="#concept-range-end" title="concept-range-end">end</a> is (<var title="">first partially contained
    child</var>, <a href="#concept-node-length" title="concept-node-length">length</a> of <var title="">first partially contained child</var>).

    <li>Let <var title="">subfrag</var> be the result of calling <code title="dom-Range-cloneContents"><a href="#dom-range-clonecontents">cloneContents()</a></code> on <var title="">subrange</var>.

    <p class="XXX">Is this method of recursing black-box detectable?  E.g., would
    it fire extra DOM mutation events or something?  What we really mean is to
    get a list of nodes to insert, then insert them directly into <var title="">frag</var>, without an intermediate document fragment.

   <li><p>For each <a href="#concept-tree-child" title="concept-tree-child">child</a> of
   <var title="">subfrag</var>, in
   <a href="#concept-tree-order" title="concept-tree-order">tree order</a>,
   <a href="#concept-node-append" title="concept-node-append">append</a> that
   <a href="#concept-tree-child" title="concept-tree-child">child</a> to <var title="">clone</var>.
  </ol>

 <li>
  <p>For each <var title="">contained child</var> in
  <var title="">contained children</var>:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">contained child</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.
  </ol>

 <li>
  <p>If <var title="">last partially contained child</var> is a
  <code><a href="#text">Text</a></code> or <code><a href="#comment">Comment</a></code>
  <a href="#concept-node" title="concept-node">node</a>:

  <p class="note">In this case, the last partially contained child is the
  original end node.

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">original end node</var>.

   <li><p>Set the <a href="#concept-cd-data" title="concept-CD-data">data</a> of
   <var title="">clone</var> to the result of
   <a href="#concept-cd-substring" title="concept-CD-substring">substringing data</a> with node
   <var title="">original end node</var>, offset 0, and count
   <var title="">original end offset</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.
  </ol>

 <li>
  <p>Otherwise, if <var title="">last partially contained child</var> is not
  null:

  <ol>
   <li><p>Let <var title="">clone</var> be a
   <a href="#concept-node-clone" title="concept-node-clone">clone</a> of
   <var title="">last partially contained child</var>.

   <li><p><a href="#concept-node-append" title="concept-node-append">Append</a> <var title="">clone</var>
   to <var title="">frag</var>.

    <li>Let <var title="">subrange</var> be a new <code><a href="#range">Range</a></code> whose <a href="#concept-range-start" title="concept-range-start">start</a> is (<var title="">last partially
    contained child</var>, 0) and whose <a href="#concept-range-end" title="concept-range-end">end</a> is (<var title="">original end node</var>,
    <var title="">original end offset</var>).

    <li>Let <var title="">subfrag</var> be the result of calling <code title="dom-Range-cloneContents"><a href="#dom-range-clonecontents">cloneContents()</a></code> on <var title="">subrange</var>.

   <li><p>For each <a href="#concept-tree-child" title="concept-tree-child">child</a> of
   <var title="">subfrag</var>, in
   <a href="#concept-tree-order" title="concept-tree-order">tree order</a>,
   <a href="#concept-node-append" title="concept-node-append">append</a> that
   <a href="#concept-tree-child" title="concept-tree-child">child</a> to <var title="">clone</var>.
  </ol>

 <li><p>Return <var title="">frag</var>.
</ol>

<p>The
<dfn id="dom-range-insertnode" title="dom-Range-insertNode"><code>insertNode(<var>node</var>)</code></dfn>
method must run these steps:

<ol>
  <!-- IE9 and Opera 11.00 throw "WrongDocumentError" if the documents don't
  match, as is their wont, and as DOM 2 Range requires. But as elsewhere, we
  just let the UA change the document if it doesn't match.

  Chrome 12 dev also throws "HierarchyRequestError" if node is the same
  as the start node (at least for text nodes). This doesn't seem to make
  much sense, since insertBefore() works fine to move a node to its current
  position, and other browsers disagree, so the spec follows the majority.
  -->

 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is a
 <code><a href="#comment">Comment</a></code> node, or a <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> whose <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> is null, <a href="#concept-throw" title="concept-throw">throw</a> an "<code><a href="#hierarchyrequesterror">HierarchyRequestError</a></code>"
 exception and terminate these steps.
 <!--
 Behavior for Text node with null parent:

 IE9: Allows it to go through, resulting in the text/comment node having a non-null previousSibling but a null parentNode. (?!)
 Firefox 4.0: Throws non-standard exception
 Chrome 12 dev: Throws "HierarchyRequestError"
 Opera 11.00: Doesn't come up, doesn't allow ranges on detached nodes

 IE is clearly crazy, and non-standard exceptions are no good, so we go with
 WebKit.

 For a Comment node, see https://www.w3.org/Bugs/Public/show_bug.cgi?id=15350.
 IE9, Firefox 12.0a1, and Chrome 17 dev all agree on throwing a
 HierarchyRequestError.  Opera Next 12.00 alpha splits the comment, same as a
 text node.
 -->

 <!-- IE9 and Chrome 12 dev throw an exception before splitting the text
 node if the insertBefore() is going to throw an exception (at least if the
 new node is the parent of the start node, for instance). Firefox 4.0 and
 Opera 11.00 don't, and the latter behavior is much easier to spec, so
 that's what I go with.

 IE9 doesn't call splitText() if the offset is 0. This makes sense, but I go
 with what all other browsers do. -->
 <li><p>If <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is a
 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-text-split" title="concept-Text-split">split</a> it with offset
 <a href="#context-object">context object</a>'s
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>, and let
 <var title="">reference node</var> be the result.

 <li><p>Otherwise, let <var title="">reference node</var> be the
 <a href="#concept-tree-child" title="concept-tree-child">child</a> of
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> whose
 <a href="#concept-tree-index" title="concept-tree-index">index</a> is
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a>, or null if
 there is no such <a href="#concept-tree-child" title="concept-tree-child">child</a>.

 <li><p>If <var title="">reference node</var> is null, let
 <var title="">parent</var> be
 <a href="#concept-range-start-node" title="concept-range-start-node">start node</a>.

 <li><p>Otherwise, let <var title="">parent</var> be the
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> of
 <var title="">reference node</var>.

 <!-- Browsers disagree on how to handle the case where the range is
 collapsed: do you increment the end offset so the node is now included, or
 not?  DOM 2 Range says no, and Firefox 12.0a1 follows that, but IE9, Chrome
 17 dev, and Opera Next 12.00 alpha all do increment.  Apparently this
 traces back to Acid3 at one point requiring the non-standard behavior.
 Previously the spec matched DOM 2 Range, but it changed to match the
 majority of browsers.  See
 https://www.w3.org/Bugs/Public/show_bug.cgi?id=15297.

 We have to be careful here, because if node is a DocumentFragment, we might
 have inserted any number of nodes, including zero.  One corner case is if
 we insert an empty DocumentFragment and the range is collapsed in a text
 node.  In that case, the text node gets split, but browsers disagree on
 what to do with the range's end.  IE9 leaves it in place; Chrome 17 dev
 moves it to the parent element, before the reference node; Opera Next 12.00
 alpha moves it to the beginning of the new text node.  The spec follows
 WebKit just because it happens to be easier for me to spec.

 The logic for how much to increment the position by is copied from the
 "insert" algorithm.  Getting the new offset right was surprisingly tricky.
 -->
 <li><p>Let <var title="">new offset</var> be the
 <a href="#concept-tree-index" title="concept-tree-index">index</a> of
 <var title="">reference node</var>, or <var title="">parent</var>'s
 <a href="#concept-node-length" title="concept-node-length">length</a> if
 <var title="">reference node</var> is null.

 <li><p>Add <var title="">node</var>'s
 <a href="#concept-node-length" title="concept-node-length">length</a> to
 <var title="">new offset</var>, if <var title="">node</var> is a
 <code><a href="#documentfragment">DocumentFragment</a></code>.  Otherwise add one to
 <var title="">new offset</var>.

 <li><p><a href="#concept-node-pre-insert" title="concept-node-pre-insert">Pre-insert</a>
 <var title="">node</var> into <var title="">parent</var> before
 <var title="">reference node</var>.

 <li><p>If <a href="#concept-range-start" title="concept-range-start">start</a> and
 <a href="#concept-range-end" title="concept-range-end">end</a> are the same, set
 <a href="#concept-range-end" title="concept-range-end">end</a> to (<var title="">parent</var>,
 <var title="">new offset</var>).
</ol>

<p>The
<dfn id="dom-range-surroundcontents" title="dom-Range-surroundContents"><code>surroundContents(<var>newParent</var>)</code></dfn>
method must run these steps:

<!--
IE9 and Chrome 12 dev throw exceptions before doing any DOM mutations in at
least some cases, so they don't wind up modifying the DOM halfway. Like if you
try surrounding a selection with an ancestor. As with insertNode(), this is
slightly nicer, but Firefox 4.0 and Opera 11.00 don't do this, and their
behavior is slightly easier to spec, so I go with them for exceptions that are
thrown by things we call, like insertNode(). However, for
BAD_BOUNDARYPOINTS_ERR/INVALID_NODE_TYPE_ERR that we throw ourselves, I do the
check first thing, which matches everyone but Firefox.
-->

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If a non-<code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a> is
 <a href="#partially-contained">partially contained</a> in the <a href="#context-object">context object</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.
 <!-- Makes some sense: otherwise we'd clone a bunch of containers, which is
 unexpected. -->
 <!-- XXX Could we rephrase this condition to be more algorithmic and less
 declarative?-->

 <li><p>If <var title="">newParent</var> is a <code><a href="#document">Document</a></code>,
 <code><a href="#documenttype">DocumentType</a></code>, or <code><a href="#documentfragment">DocumentFragment</a></code>
 <a href="#concept-node" title="concept-node">node</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.
 <!-- But for Comment, Text, and ProcessingInstruction, we just fall through
 and throw a HIERARCHY_REQUEST_ERR when we try appendChild(). This makes
 absolutely no sense, but it's what DOM 2 Range specifies, and it's what
 IE9, Chrome 12 dev, and Opera 11.00 implement. Firefox 4.0 only throws
 INVALID_NODE_TYPE_ERR on DocumentFragments, it falls through to
 HIERARCHY_REQUEST_ERR for Documents and DocumentTypes.

 Firefox 4.0 does this check later on, so it will do DOM mutations of some
 type if passed a DocumentFragment. We match IE9, Chrome 12 dev, and Opera
 11.00 in doing the check early.

 If newParent is a Document/DocumentType/DocumentFragment, and some node is
 also partially contained, DOM 2 Range doesn't say whether to throw
 BAD_BOUNDARYPOINTS_ERR or INVALID_NODE_TYPE_ERR. IE9 and Chrome 12 dev
 throw INVALID_NODE_TYPE_ERR, while Firefox 4.0 and Opera 11.00 throw
 BAD_BOUNDARYPOINTS_ERR. I chose the latter because it's the first thing I
 happened to write down and it makes no real difference, with the even
 split. -->

  <li>Call <code title="dom-Range-extractContents"><a href="#dom-range-extractcontents">extractContents()</a></code> on
  the <a href="#context-object">context object</a>, and let <var title="">fragment</var> be the
  result.
  <!-- If the range contains a DocumentType, Firefox 4.0 and Opera 11.00 don't
  immediately throw here. Firefox removes the non-DocumentType nodes and
  throws, Opera removes all nodes and doesn't throw. This applies to
  extractContents() proper, and also affects surroundContents(). I match DOM 2
  Range, IE9, and Chrome 12 dev. -->

 <li><p>While <var title="">newParent</var> has
 <a href="#concept-tree-child" title="concept-tree-child">children</a>, remove its first
 <a href="#concept-tree-child" title="concept-tree-child">child</a>.
 <!-- XXX concept-node-remove -->

  <li>Call <code title="dom-Range-insertNode"><a href="#dom-range-insertnode">insertNode(<var title="">newParent</var>)</a></code> on the <a href="#context-object">context object</a>.

  <li>Call <code title="dom-Node-appendChild"><a href="#dom-node-appendchild">appendChild(<var title="">fragment</var>)</a></code> on
  <var title="">newParent</var>.

  <li>Call <code title="dom-Range-selectNode"><a href="#dom-range-selectnode">selectNode(<var title="">newParent</var>)</a></code> on the <a href="#context-object">context object</a>.
  <!-- Generally this isn't needed, because insertNode() will already do it,
  but it makes a difference in at least one corner case (when the original
  range lies in a single text node). -->
</ol>

<p>The <dfn id="dom-range-clonerange" title="dom-Range-cloneRange"><code>cloneRange()</code></dfn>
method must <a href="#concept-throw" title="concept-throw">throw</a> an
"<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception if the
<a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is set. Otherwise,
it must return a new <a href="#concept-range" title="concept-range">range</a> with the same
<a href="#concept-range-start" title="concept-range-start">start</a> and
<a href="#concept-range-end" title="concept-range-end">end</a> as the <a href="#context-object">context object</a>.

<p>The <dfn id="dom-range-detach" title="dom-Range-detach"><code>detach()</code></dfn> method must
run these steps:
<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Set the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a>.
</ol>

<hr>

<dl class="domintro">
 <dt><var title="">position</var> = <var title="">range</var> . <code title="dom-Range-comparePoint"><a href="#dom-range-comparepoint">comparePoint</a></code>( <var title="">parent</var>, <var title="">offset</var> )
 <dd><p>Returns &minus;1 if the point is before the range, 0 if the point is
 in the range, and 1 if the point is after the range.

 <dt><var title="">intersects</var> = <var title="">range</var> . <code title="dom-Range-intersectsNode"><a href="#dom-range-intersectsnode">intersectsNode</a></code>( <var title="">node</var> )
 <dd><p>Returns whether <var title="">range</var> intersects
 <var title="">node</var>.
</dl>

<div class="impl">

<p>The
<dfn id="dom-range-ispointinrange" title="dom-Range-isPointInRange"><code>isPointInRange(<var>node</var>, <var>offset</var>)</code></dfn>
must run these steps:
<!-- Tested October 2011 on Firefox 9.0a2 and Chrome 16 dev.  IE9 and Opera
11.50 don't support the method. -->

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">node</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a> is
 different from the <a href="#context-object">context object</a>'s <a href="#concept-range-root" title="concept-range-root">root</a>, return false and terminate these steps.
 <!-- This happens even if the offset is negative or too large, or if the node
 is a doctype, in both Firefox 9.0a2 and Chrome 16 dev. -->

 <li><p>If <var title="">node</var> is a
 <a href="#concept-doctype" title="concept-doctype">doctype</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.
 <!-- Firefox 9.0a2 doesn't throw.  It ignores the offset and returns true or
 false depending on whether the doctype itself is in the range.  This makes
 some sense, but it doesn't match how other Range APIs handle doctypes, and
 having the second argument mandatory but ignored is just weird.  Thus I go
 with Chrome 16 dev, although I can see the merit in how Gecko works here. -->

 <li><p>If <var title="">offset</var> is greater than
 <var title="">node</var>'s <a href="#concept-node-length" title="concept-node-length">length</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.
 <!-- Firefox 9.0a2 doesn't throw.  It seems to return true if the node is
 completely contained in the range, like with selectNode(), and false otherwise
 - even if all boundary points in the node are contained in the range, like
 with selectNodeContents().  This is weird, and inconsistent with other Range
 APIs, so I go with Chrome 16 dev.  This is probably an authoring bug, so it's
 best to throw anyway. -->

 <li><p>If (<var title="">node</var>, <var title="">offset</var>) is
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>
 <a href="#concept-range-start" title="concept-range-start">start</a> or
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>
 <a href="#concept-range-end" title="concept-range-end">end</a>, return false and terminate these
 steps.

 <li><p>Return true.
</ol>


<p>The
<dfn id="dom-range-comparepoint" title="dom-Range-comparePoint"><code>comparePoint(<var>node</var>, <var>offset</var>)</code></dfn>
method must run these steps:
<!-- IE9 doesn't support this method at all.  Firefox 12.0a1, Chrome 17 dev,
and Opera Next 12.00 alpha all do. -->

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>If <var title="">node</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a> is
 different from the <a href="#context-object">context object</a>'s
 <a href="#concept-range-root" title="concept-range-root">root</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#wrongdocumenterror">WrongDocumentError</a></code>"
 exception and terminate these steps.
 <!-- Opera Next 12.00 alpha seems to return -1 in this case.  The spec matches
 Firefox 12.0a1 and Chrome 17 dev. -->

 <li><p>If <var title="">node</var> is a
 <a href="#concept-doctype" title="concept-doctype">doctype</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidnodetypeerror">InvalidNodeTypeError</a></code>" exception and terminate these
 steps.
 <!-- This matches Chrome 17 dev instead of Firefox 12.0a1 and Opera Next 12.00
 alpha, which don't throw and seem to just ignore the offset instead.  See
 comment for isPointInRange(). -->

 <li><p>If <var title="">offset</var> is greater than
 <var title="">node</var>'s <a href="#concept-node-length" title="concept-node-length">length</a>,
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#indexsizeerror">IndexSizeError</a></code>" exception and terminate these steps.
 <!-- This matches Chrome 17 dev instead of Firefox 12.0a1 and Opera Next 12.00
 alpha, which don't throw.  See comment for isPointInRange(). -->

 <li><p>If (<var title="">node</var>, <var title="">offset</var>) is
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>
 <a href="#concept-range-start" title="concept-range-start">start</a>, return &minus;1 and terminate
 these steps.

 <li><p>If (<var title="">node</var>, <var title="">offset</var>) is
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>
 <a href="#concept-range-end" title="concept-range-end">end</a>, return 1 and terminate these steps.

 <li><p>Return 0.
</ol>

<hr>

<p>The
<dfn id="dom-range-intersectsnode" title="dom-Range-intersectsNode"><code>intersectsNode(<var>node</var>)</code></dfn>
method must run these steps:
<!-- Supported by Chrome 17 dev and Opera Next 12.00 alpha, but not IE9 or
Firefox 12.0a1. -->

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.
 <!-- Oddly, neither Chrome 17 dev nor Opera Next 12.00 alpha consistently
 throws here.  This is inconsistent with all other Range methods, so I
 mandate it anyway despite no implementation doing it. -->

 <li><p>If <var title="">node</var>'s <a href="#concept-tree-root" title="concept-tree-root">root</a>
 is different from the <a href="#context-object">context object</a>'s
 <a href="#concept-range-root" title="concept-range-root">root</a>, return false and terminate
 these steps.
 <!-- It seems like for doctypes, Opera Next 12.00 alpha throws
 InvalidNodeTypeError instead of returning false.  The spec follows Chrome
 17 dev. -->

 <li><p>Let <var title="">parent</var> be <var title="">node</var>'s
 <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

 <li><p>If <var title="">parent</var> is null, <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#notfounderror">NotFoundError</a></code>" exception
 and terminate these steps.
 <!-- Opera Next 12.00 alpha seems to throw InvalidNodeTypeError instead.
 The spec follows Chrome 17 dev. -->

 <p class="XXX">All implementations throw in this case, but would it make more
 sense to simply return true?  This case can only occur when the roots are
 the same, so it means that <var title="">node</var> is the range's root, so
 the range is fully contained in <var title="">node</var>.

 <li><p>Let <var title="">offset</var> be <var title="">node</var>'s
 <a href="#concept-tree-index" title="concept-tree-index">index</a>.

 <li><p>If (<var title="">parent</var>, <var title="">offset</var>) is
 <a href="#concept-range-bp-before" title="concept-range-bp-before">before</a>
 <a href="#concept-range-end" title="concept-range-end">end</a> and (<var title="">parent</var>,
 <var title="">offset</var> + 1) is
 <a href="#concept-range-bp-after" title="concept-range-bp-after">after</a>
 <a href="#concept-range-start" title="concept-range-start">start</a>, return true and terminate
 these steps.

 <li><p>Return false.
</ol>

</div>

<hr>

<p>The <dfn id="dom-range-stringifier" title="dom-Range-stringifier">stringifier</dfn> must run these
steps:

<ol>
 <li><p>If the <a href="#concept-range-detached" title="concept-range-detached">detached flag</a> is
 set, <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">s</var> be the empty string.

 <li><p>If <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> equals
 <a href="#concept-range-end-node" title="concept-range-end-node">end node</a>, and it is a
 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>, return the
 substring of that <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>'s <a href="#concept-cd-data" title="concept-CD-data">data</a> beginning at
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> and ending at
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>, and terminate these
 steps.

 <li><p>If <a href="#concept-range-start-node" title="concept-range-start-node">start node</a> is a
 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>, append to
 <var title="">s</var> the substring of that
 <a href="#concept-node" title="concept-node">node</a>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a> from the
 <a href="#concept-range-start-offset" title="concept-range-start-offset">start offset</a> until the end.

 <li><p>Append to <var title="">s</var> the concatenation, in
 <a href="#concept-tree-order" title="concept-tree-order">tree order</a>, of the
 <a href="#concept-cd-data" title="concept-CD-data">data</a> of all <code><a href="#text">Text</a></code>
 <a href="#concept-node" title="concept-node">nodes</a> that are <a href="#contained">contained</a> in
 the <a href="#context-object">context object</a>.

 <li><p>If <a href="#concept-range-end-node" title="concept-range-end-node">end node</a> is a
 <code><a href="#text">Text</a></code> <a href="#concept-node" title="concept-node">node</a>, append to
 <var title="">s</var> the substring of that
 <a href="#concept-node" title="concept-node">node</a>'s
 <a href="#concept-cd-data" title="concept-CD-data">data</a> from its start until the
 <a href="#concept-range-end-offset" title="concept-range-end-offset">end offset</a>.

 <li><p>Return <var title="">s</var>.
</ol>

<hr>

<div class="note">
<p>The following extensions to the <code><a href="#range">Range</a></code> interface are defined
in various other specifications:
<ul>
 <li>the <code class="external" title="dom-Range-createContextualFragment"><a href="http://html5.org/specs/dom-parsing.html#dom-range-createcontextualfragment">createContextualFragment()</a></code> method;
 <a class="informative" href="#refsDOMPS">[DOMPS]</a>
 <li>the <code class="external" title="dom-Range-getClientRects"><a href="http://dev.w3.org/csswg/cssom-view/#dom-range-getclientrects">getClientRects()</a></code> method; and
 <li>the <code class="external" title="dom-Range-getBoundingClientRect"><a href="http://dev.w3.org/csswg/cssom-view/#dom-range-getboundingclientrect">getBoundingClientRect()</a></code> method.
 <a class="informative" href="#refsCSSOMVIEW">[CSSOMVIEW]</a>
</ul>
</div>



<h2 id="traversal"><span class="secno">7 </span>Traversal</h2>

<p><code><a href="#nodeiterator">NodeIterator</a></code> and <code><a href="#treewalker">TreeWalker</a></code> objects can be used
to filter and traverse <a href="#concept-node" title="concept-node">node</a>
<a href="#concept-tree" title="concept-tree">trees</a>.

<p>Each <code><a href="#nodeiterator">NodeIterator</a></code> and <code><a href="#treewalker">TreeWalker</a></code> object has an
associated <dfn id="concept-traversal-active" title="concept-traversal-active">active flag</dfn> to avoid
recursive invocations. It is initially unset.

<p>Each <code><a href="#nodeiterator">NodeIterator</a></code> and <code><a href="#treewalker">TreeWalker</a></code> object also
has an associated <dfn id="concept-traversal-root" title="concept-traversal-root">root</dfn>
<a href="#concept-node" title="concept-node">node</a>,
<dfn id="concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</dfn> bitmask, and
<dfn id="concept-traversal-filter" title="concept-traversal-filter">filter</dfn> callback.

<p>To <dfn id="concept-node-filter" title="concept-node-filter">filter</dfn> <var title="">node</var> run
these steps:

<ol>
 <li><p>If <a href="#concept-traversal-active" title="concept-traversal-active">active flag</a> is set
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>", terminate these steps, and
 terminate the steps of the algorithm that invoked this algorithm.
 <li><p>Let <var title="">n</var> be <var title="">node</var>'s
 <code title="dom-Node-nodeType"><a href="#dom-node-nodetype">nodeType</a></code> attribute value minus 1.
 <li><p>If the <var title="">n</var><sup>th</sup> bit (where 0 is the least
 significant bit) of
 <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> is not set,
 return <code title="dom-NodeFilter-FILTER_SKIP"><a href="#dom-nodefilter-filter_skip">FILTER_SKIP</a></code> and
 terminate these steps.
 <!-- !((1 << (node.nodeType - 1)) & whatToShow) -->
 <li><p>If <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> is null return
 <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code> and terminate
 these steps.
 <li><p>Set the <a href="#concept-traversal-active" title="concept-traversal-active">active flag</a>.
 <li><p>Let <var title="">result</var> be the return value of invoking
 <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a>.
 <li><p>Unset the <a href="#concept-traversal-active" title="concept-traversal-active">active flag</a>.
 <li><p>If an exception was thrown, re-throw the exception, terminate these
 steps, and terminate the steps of the algorithm that invoked this
 algorithm.
 <li><p>Return <var title="">result</var>.
</ol>


<h3 id="interface-nodeiterator"><span class="secno">7.1 </span>Interface <code><a href="#nodeiterator">NodeIterator</a></code></h3>

<pre class="idl">interface <dfn id="nodeiterator">NodeIterator</dfn> {
  readonly attribute <a href="#node">Node</a> <a href="#dom-nodeiterator-root" title="dom-NodeIterator-root">root</a>;
  readonly attribute <a href="#node">Node</a>? <a href="#dom-nodeiterator-referencenode" title="dom-NodeIterator-referenceNode">referenceNode</a>;
  readonly attribute boolean <a href="#dom-nodeiterator-pointerbeforereferencenode" title="dom-NodeIterator-pointerBeforeReferenceNode">pointerBeforeReferenceNode</a>;
  readonly attribute unsigned long <a href="#dom-nodeiterator-whattoshow" title="dom-NodeIterator-whatToShow">whatToShow</a>;
  readonly attribute <a href="#nodefilter">NodeFilter</a>? <a href="#dom-nodeiterator-filter" title="dom-NodeIterator-filter">filter</a>;<!--
  readonly attribute boolean <span title=dom-NodeIterator-expandEntityReferences>expandEntityReferences</span>;-->

  <a href="#node">Node</a>? <a href="#dom-nodeiterator-nextnode" title="dom-NodeIterator-nextNode">nextNode</a>();
  <a href="#node">Node</a>? <a href="#dom-nodeiterator-previousnode" title="dom-NodeIterator-previousNode">previousNode</a>();

  void <a href="#dom-nodeiterator-detach" title="dom-NodeIterator-detach">detach</a>();
};</pre>

<p class="note"><code><a href="#nodeiterator">NodeIterator</a></code> objects can be created using the
<code title="dom-Document-createNodeIterator"><a href="#dom-document-createnodeiterator">createNodeIterator()</a></code>
method.

<p>Each <code><a href="#nodeiterator">NodeIterator</a></code> object has an associated
<dfn id="iterator-collection">iterator collection</dfn>, which is a
<a href="#concept-collection" title="concept-collection">collection</a> rooted at
<a href="#concept-traversal-root" title="concept-traversal-root">root</a>, whose filter matches any
<a href="#concept-node" title="concept-node">node</a>.

<p>Before a <a href="#concept-node" title="concept-node">node</a> is removed from the
<a href="#iterator-collection">iterator collection</a>, these steps must be run:

<ol>
 <li><p>If the <a href="#concept-node" title="concept-node">node</a> is not a
 <a href="#concept-tree-descendant" title="concept-tree-descendant">descendant</a> of
 <a href="#concept-traversal-root" title="concept-traversal-root">root</a> and is not an
 <a href="#concept-tree-ancestor" title="concept-tree-ancestor">ancestor</a> of the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 value or the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 value itself, terminate these steps.

 <li><p>If the
 <code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
 attribute value is false, set the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 to the first <a href="#concept-node" title="concept-node">node</a>
 <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a> the
 <a href="#concept-node" title="concept-node">node</a> that is being removed, and terminate
 these steps.

 <li><p>If the
 <code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
 attribute value is true and there is a <a href="#concept-node" title="concept-node">node</a>
 <a href="#concept-tree-following" title="concept-tree-following">following</a> the
 <a href="#concept-node" title="concept-node">node</a> that is being removed, set the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 to the first such <a href="#concept-node" title="concept-node">node</a>, and terminate these
 steps.

 <li><p>Set the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 to the first <a href="#concept-node" title="concept-node">node</a>
 <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a> the
 <a href="#concept-node" title="concept-node">node</a> that is being removed and set the
 <code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
 attribute to false.
</ol>


<p>Each <code><a href="#nodeiterator">NodeIterator</a></code> object also has an associated
<dfn id="detached-flag">detached flag</dfn> which is initially unset.

<p class="note">As mentioned earlier <code><a href="#nodeiterator">NodeIterator</a></code> objects have an
associated <a href="#concept-traversal-active" title="concept-traversal-active">active flag</a>,
<a href="#concept-traversal-root" title="concept-traversal-root">root</a>
<a href="#concept-node" title="concept-node">node</a>,
<a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> bitmask, and
<a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> callback as well.

<hr>

<p>The <dfn id="dom-nodeiterator-root" title="dom-NodeIterator-root"><code>root</code></dfn> attribute
must return <a href="#concept-traversal-root" title="concept-traversal-root">root</a>.</p>

<p>The
<dfn id="dom-nodeiterator-referencenode" title="dom-NodeIterator-referenceNode"><code>referenceNode</code></dfn>
attribute must return what it was initialized to.</p>

<p>The
<dfn id="dom-nodeiterator-pointerbeforereferencenode" title="dom-NodeIterator-pointerBeforeReferenceNode"><code>pointerBeforeReferenceNode</code></dfn>
attribute must return what it was initialized to. When a
<code><a href="#nodeiterator">NodeIterator</a></code> is created it must be initialized to true.</p>

<p>The <dfn id="dom-nodeiterator-whattoshow" title="dom-NodeIterator-whatToShow"><code>whatToShow</code></dfn>
attribute must return
<a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a>.

<p>The <dfn id="dom-nodeiterator-filter" title="dom-NodeIterator-filter"><code>filter</code></dfn>
attribute must return <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a>.

<p>To <dfn id="concept-nodeiterator-traverse" title="concept-NodeIterator-traverse">traverse</dfn> in direction
<var title="">direction</var> run these steps:

<ol>
 <li><p>If the <a href="#detached-flag">detached flag</a> is set
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these steps.

 <li><p>Let <var title="">node</var> be the value of the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute.

 <li><p>Let <var title="">before node</var> be the value of the
 <code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
 attribute.

 <li>
  <p>Run these substeps:
  <ol>
   <li>
    <dl class="switch">
     <dt>If direction is next</dt>
     <dd>
      <p>If <var title="">before node</var> is false, let <var title="">node</var>
      be the first <a href="#concept-node" title="concept-node">node</a>
      <a href="#concept-tree-following" title="concept-tree-following">following</a>
      <var title="">node</var> in the <a href="#iterator-collection">iterator collection</a>. If
      there is no such <a href="#concept-node" title="concept-node">node</a> return null and
      terminate these steps.
      <p>If <var title="">before node</var> is true, set it to false.
     <dt>If direction is previous</dt>
     <dd>
      <p>If <var title="">before node</var> is true, let <var title="">node</var>
      be the first <a href="#concept-node" title="concept-node">node</a>
      <a href="#concept-tree-preceding" title="concept-tree-preceding">preceding</a>
      <var title="">node</var> in the <a href="#iterator-collection">iterator collection</a>. If
      there is no such <a href="#concept-node" title="concept-node">node</a> return null and
      terminate these steps.
      <p>If <var title="">before node</var> is false, set it to true.
    </dl>
   <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
   <var title="">node</var> and let <var title="">result</var> be the return
   value.
   <li><p>If the <a href="#detached-flag">detached flag</a> is set
   <a href="#concept-throw" title="concept-throw">throw</a> an
   "<code><a href="#invalidstateerror">InvalidStateError</a></code>" exception and terminate these
   steps.
   <li>
    <p>If <var title="">result</var> is
    <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, go to the
    next step in the overall set of steps.
    <p>Otherwise, run these substeps again.
  </ol>
 <li><p>Set the
 <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute
 to <var title="">node</var>, set the
 <code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
 attribute to <var title="">before node</var>, and return
 <var title="">node</var>.
</ol>

<p>The <dfn id="dom-nodeiterator-nextnode" title="dom-NodeIterator-nextNode"><code>nextNode()</code></dfn>
method must <a href="#concept-nodeiterator-traverse" title="concept-NodeIterator-traverse">traverse</a> in
direction next.

<p>The
<dfn id="dom-nodeiterator-previousnode" title="dom-NodeIterator-previousNode"><code>previousNode()</code></dfn>
method must <a href="#concept-nodeiterator-traverse" title="concept-NodeIterator-traverse">traverse</a> in
direction previous.

<p>When the <dfn id="dom-nodeiterator-detach" title="dom-NodeIterator-detach"><code>detach()</code></dfn>
method is invoked set the <a href="#detached-flag">detached flag</a> and set the
<code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> attribute to
null.


<h3 id="interface-treewalker"><span class="secno">7.2 </span>Interface <code><a href="#treewalker">TreeWalker</a></code></h3>

<pre class="idl">interface <dfn id="treewalker">TreeWalker</dfn> {
  readonly attribute <a href="#node">Node</a> <a href="#dom-treewalker-root" title="dom-TreeWalker-root">root</a>;
  readonly attribute unsigned long <a href="#dom-treewalker-whattoshow" title="dom-TreeWalker-whatToShow">whatToShow</a>;
  readonly attribute <a href="#nodefilter">NodeFilter</a>? <a href="#dom-treewalker-filter" title="dom-TreeWalker-filter">filter</a>;<!--
  readonly attribute boolean <span title=dom-TreeWalker-expandEntityReferences>expandEntityReferences</span>;-->
           attribute <a href="#node">Node</a> <a href="#dom-treewalker-currentnode" title="dom-TreeWalker-currentNode">currentNode</a>;

  <a href="#node">Node</a>? <a href="#dom-treewalker-parentnode" title="dom-TreeWalker-parentNode">parentNode</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-firstchild" title="dom-TreeWalker-firstChild">firstChild</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-lastchild" title="dom-TreeWalker-lastChild">lastChild</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-previoussibling" title="dom-TreeWalker-previousSibling">previousSibling</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-nextsibling" title="dom-TreeWalker-nextSibling">nextSibling</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-previousnode" title="dom-TreeWalker-previousNode">previousNode</a>();
  <a href="#node">Node</a>? <a href="#dom-treewalker-nextnode" title="dom-TreeWalker-nextNode">nextNode</a>();
};</pre>

<p class="note"><code><a href="#treewalker">TreeWalker</a></code> objects can be created using the
<code title="dom-Document-createTreeWalker"><a href="#dom-document-createtreewalker">createTreeWalker()</a></code> method.

<p class="note">As mentioned earlier <code><a href="#treewalker">TreeWalker</a></code> objects have an
associated <a href="#concept-traversal-active" title="concept-traversal-active">active flag</a>,
<a href="#concept-traversal-root" title="concept-traversal-root">root</a>
<a href="#concept-node" title="concept-node">node</a>,
<a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> bitmask, and
<a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> callback.

<p>The <dfn id="dom-treewalker-root" title="dom-TreeWalker-root"><code>root</code></dfn> attribute must
return <a href="#concept-traversal-root" title="concept-traversal-root">root</a>.</p>

<p>The <dfn id="dom-treewalker-whattoshow" title="dom-TreeWalker-whatToShow"><code>whatToShow</code></dfn>
attribute must return
<a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a>.

<p>The <dfn id="dom-treewalker-filter" title="dom-TreeWalker-filter"><code>filter</code></dfn> attribute
must return <a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a>.

<p>The <dfn id="dom-treewalker-currentnode" title="dom-TreeWalker-currentNode"><code>currentNode</code></dfn>
attribute must return what it was initialized to.</p>

<p>Setting the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code>
attribute must set it to the new value.</p>


<p>The <dfn id="dom-treewalker-parentnode" title="dom-TreeWalker-parentNode"><code>parentNode()</code></dfn>
method must run these steps:

<ol>
 <li><p>Let <var title="">node</var> be the value of the
 <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute.

 <li>
  <p>While <var title="">node</var> is not null and is not
  <a href="#concept-traversal-root" title="concept-traversal-root">root</a>, run these substeps:

  <ol>
   <li><p>Let <var title="">node</var> be <var title="">node</var>'s
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

   <li><p>If <var title="">node</var> is not null and
   <a href="#concept-node-filter" title="concept-node-filter">filtering</a> <var title="">node</var>
   returns <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>,
   then set the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code>
   attribute to <var title="">node</var>, return <var title="">node</var>, and
   terminate these steps.
  </ol>

 <li><p>Return null.
</ol>

<p>To <dfn id="concept-traverse-children" title="concept-traverse-children">traverse children</dfn> of type
<var title="">type</var> run these steps:

<ol>
 <li><p>Let <var title="">node</var> and <var title="">current</var> be the value
 of the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute.

 <li>
  <p>While <var title="">node</var> is not null, run these substeps:

  <ol>
   <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
   <var title="">node</var> and let <var title="">result</var> be the return
   value.

   <li><p>If <var title="">result</var> is
   <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
   the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code>
   attribute to <var title="">node</var>, return <var title="">node</var>, and
   terminate these steps.

   <li>
    <p>If <var title="">result</var> is
    <code title="dom-NodeFilter-FILTER_SKIP"><a href="#dom-nodefilter-filter_skip">FILTER_SKIP</a></code> and
    <var title="">node</var> has a <a href="#concept-tree-child" title="concept-tree-child">child</a>,
    then set <var title="">node</var> as follows and run these substeps again:

    <dl class="switch">
     <dt>If type is first
     <dd><p>Set it to the
     <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>
     <dt>If type is last
     <dd><p>Set it to the
     <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>
    </dl>

   <li>
    <p>While <var title="">node</var> is not null, run these inner substeps:

    <ol>
     <li>
      <dl class="switch">
       <dt>If type is first
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a> of
       <var title="">node</var>.
       <dt>If type is last
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a> of
       <var title="">node</var>.
      </dl>

     <li><p>If <var title="">sibling</var> is not null, set
     <var title="">node</var> to it and terminate these inner substeps.

     <!-- bring it on jgraham -->

     <li>
      <p>If <var title="">node</var> has a
      <a href="#concept-tree-parent" title="concept-tree-parent">parent</a> that is not
      <a href="#concept-traversal-root" title="concept-traversal-root">root</a> or
      <var title="">current</var> then set <var title="">node</var> to it.

      <p>Otherwise, return null and terminate these steps.
    </ol>
  </ol>
</ol>

<p>The <dfn id="dom-treewalker-firstchild" title="dom-TreeWalker-firstChild"><code>firstChild()</code></dfn>
method must <a href="#concept-traverse-children" title="concept-traverse-children">traverse children</a>
of type first.

<p>The <dfn id="dom-treewalker-lastchild" title="dom-TreeWalker-lastChild"><code>lastChild()</code></dfn>
method must <a href="#concept-traverse-children" title="concept-traverse-children">traverse children</a>
of type last.

<p>To <dfn id="concept-traverse-siblings" title="concept-traverse-siblings">traverse siblings</dfn> of type
<var title="">type</var> run these steps:

<ol>
 <li><p>Let <var title="">node</var> be the value of the
 <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute.

 <li><p>If <var title="">node</var> is
 <a href="#concept-traversal-root" title="concept-traversal-root">root</a> return null and terminate
 these steps.

 <li>
  <p>Run these substeps:

  <ol>
   <li>
    <dl class="switch">
     <dt>If type is next
     <dd><p>Let <var title="">sibling</var> be the
     <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a> of
     <var title="">node</var>.
     <dt>If type is previous
     <dd><p>Let <var title="">sibling</var> be the
     <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a> of
     <var title="">node</var>.
    </dl>

   <li>
    <p>While <var title="">sibling</var> is not null run these inner substeps:

    <ol>
     <li><p>Set <var title="">node</var> to <var title="">sibling</var>.

     <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
     <var title="">node</var> and let <var title="">result</var> be the return
     value.

     <li><p>If <var title="">result</var> is
     <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
     the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code>
     attribute to <var title="">node</var>, return <var title="">node</var>, and
     terminate these steps.

     <li>
      <dl class="switch">
       <dt>If type is next
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a> of
       <var title="">node</var>.
       <dt>If type is previous
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a> of
       <var title="">node</var>.
      </dl>

     <li>
      <p>If <var title="">result</var> is
      <code title="dom-NodeFilter-FILTER_REJECT"><a href="#dom-nodefilter-filter_reject">FILTER_REJECT</a></code> or
      <var title="">sibling</var> is null, then set <var title="">sibling</var> as
      follows:

      <dl class="switch">
       <dt>If type is next
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-next-sibling" title="concept-tree-next-sibling">next sibling</a> of
       <var title="">node</var>.
       <dt>If type is previous
       <dd><p>Let <var title="">sibling</var> be the
       <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a> of
       <var title="">node</var>.
      </dl>
    </ol>

   <li><p>Set <var title="">node</var> to its
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

   <li><p>If <var title="">node</var> is null or is
   <a href="#concept-traversal-root" title="concept-traversal-root">root</a> return null and terminate
   these steps.

   <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
   <var title="">node</var> and if the return value is
   <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then
   return null and terminate these steps.
   <!-- XXX WTF? -->

   <li><p>Run these substeps again.
  </ol>
</ol>

<p>The
<dfn id="dom-treewalker-nextsibling" title="dom-TreeWalker-nextSibling"><code>nextSibling()</code></dfn>
method must <a href="#concept-traverse-children" title="concept-traverse-children">traverse children</a>
of type next.

<p>The
<dfn id="dom-treewalker-previoussibling" title="dom-TreeWalker-previousSibling"><code>previousSibling()</code></dfn>
method must <a href="#concept-traverse-children" title="concept-traverse-children">traverse children</a>
of type previous.

<p>The
<dfn id="dom-treewalker-previousnode" title="dom-TreeWalker-previousNode"><code>previousNode()</code></dfn>
method must run these steps:

<ol>
 <li><p>Let <var title="">node</var> be the value of the
 <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute.

 <li>
  <p>While <var title="">node</var> is not
  <a href="#concept-traversal-root" title="concept-traversal-root">root</a> run these substeps:

  <ol>
   <li><p>Let <var title="">sibling</var> be the
   <a href="#concept-tree-previous-sibling" title="concept-tree-previous-sibling">previous sibling</a> of
   <var title="">node</var>.

   <li>
    <p>While <var title="">sibling</var> is not null run these inner substeps:

    <ol>
     <li><p>Set <var title="">node</var> to <var title="">sibling</var>.

     <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
     <var title="">node</var> and let <var title="">result</var> be the return
     value.

     <li>
      <p>While <var title="">result</var> is not
      <code title="dom-NodeFilter-FILTER_REJECT"><a href="#dom-nodefilter-filter_reject">FILTER_REJECT</a></code> and
      <var title="">node</var> has a
      <a href="#concept-tree-child" title="concept-tree-child">child</a>, run these innermost
      substeps:

      <ol>
       <li><p>Set <var title="">node</var> to its
       <a href="#concept-tree-last-child" title="concept-tree-last-child">last child</a>.

       <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
       <var title="">node</var> and set <var title="">result</var> to the return
       value.
      </ol>

     <li><p>If <var title="">result</var> is
     <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
     the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code>
     attribute to <var title="">node</var>, return <var title="">node</var>, and
     terminate these steps.
    </ol>

   <li><p>If <var title="">node</var> is
   <a href="#concept-traversal-root" title="concept-traversal-root">root</a> or has no
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>, return null and terminate
   these steps.

   <li><p>Set <var title="">node</var> to its
   <a href="#concept-tree-parent" title="concept-tree-parent">parent</a>.

   <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
   <var title="">node</var> and if the return value is
   <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
   the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute
   to <var title="">node</var>, return <var title="">node</var>, and terminate
   these steps.
  </ol>
</ol>

<p>The <dfn id="dom-treewalker-nextnode" title="dom-TreeWalker-nextNode"><code>nextNode()</code></dfn>
method must run these steps:

<ol>
 <li><p>Let <var title="">node</var> be the value of the
 <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute.

 <li><p>Let <var title="">result</var> be
 <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>.

 <li>
  <p>Run these substeps:

  <ol>
   <li>
    <p>While <var title="">result</var> is not
    <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code> and
    <var title="">node</var> has a <a href="#concept-tree-child" title="concept-tree-child">child</a>,
    run these inner substeps:

    <ol>
     <li><p>Set <var title="">node</var> to its
     <a href="#concept-tree-first-child" title="concept-tree-first-child">first child</a>

     <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
     <var title="">node</var> and let <var title="">result</var> be the return
     value.

     <li><p>If <var title="">result</var> is
     <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
     the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute
     to <var title="">node</var>, return <var title="">node</var>, and terminate
     these steps.
    </ol>

   <li>
    <p>If a <a href="#concept-node" title="concept-node">node</a> is
    <a href="#concept-tree-following" title="concept-tree-following">following</a>
    <var title="">node</var> and is not
    <a href="#concept-tree-following" title="concept-tree-following">following</a>
    <a href="#concept-traversal-root" title="concept-traversal-root">root</a>, set
    <var title="">node</var> to the first such
    <a href="#concept-node" title="concept-node">node</a>.
    <p>Otherwise, run these substeps again (skipping the next step).
    <!-- Implemented as iterating over parent/nextSibling in Gecko -->

   <li><p><a href="#concept-node-filter" title="concept-node-filter">Filter</a>
   <var title="">node</var> and if the return value is
   <code title="dom-NodeFilter-FILTER_ACCEPT"><a href="#dom-nodefilter-filter_accept">FILTER_ACCEPT</a></code>, then set
   the <code title="dom-TreeWalker-currentNode"><a href="#dom-treewalker-currentnode">currentNode</a></code> attribute
   to <var title="">node</var>, return <var title="">node</var>, and terminate
   these steps.
  </ol>
</ol>



<h3 id="interface-nodefilter"><span class="secno">7.3 </span>Interface <code><a href="#nodefilter">NodeFilter</a></code></h3>

<pre class="idl">callback interface <dfn id="nodefilter">NodeFilter</dfn> {
  // Constants for <span title="dom-NodeFilter-acceptNode">acceptNode()</span>
  const unsigned short <a href="#dom-nodefilter-filter_accept" title="dom-NodeFilter-FILTER_ACCEPT">FILTER_ACCEPT</a> = 1;
  const unsigned short <a href="#dom-nodefilter-filter_reject" title="dom-NodeFilter-FILTER_REJECT">FILTER_REJECT</a> = 2;
  const unsigned short <a href="#dom-nodefilter-filter_skip" title="dom-NodeFilter-FILTER_SKIP">FILTER_SKIP</a> = 3;

  // Constants for <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a>
  const unsigned long <a href="#dom-nodefilter-show_all" title="dom-NodeFilter-SHOW_ALL">SHOW_ALL</a> = 0xFFFFFFFF;
  const unsigned long <a href="#dom-nodefilter-show_element" title="dom-NodeFilter-SHOW_ELEMENT">SHOW_ELEMENT</a> = 0x1;
  const unsigned long <span title="dom-NodeFilter-SHOW_ATTRIBUTE">SHOW_ATTRIBUTE</span> = 0x2; // historical
  const unsigned long <a href="#dom-nodefilter-show_text" title="dom-NodeFilter-SHOW_TEXT">SHOW_TEXT</a> = 0x4;
  const unsigned long <span title="dom-NodeFilter-SHOW_CDATA_SECTION">SHOW_CDATA_SECTION</span> = 0x8; // historical
  const unsigned long <span title="dom-NodeFilter-SHOW_ENTITY_REFERENCE">SHOW_ENTITY_REFERENCE</span> = 0x10; // historical
  const unsigned long <span title="dom-NodeFilter-SHOW_ENTITY">SHOW_ENTITY</span> = 0x20; // historical
  const unsigned long <a href="#dom-nodefilter-show_processing_instruction" title="dom-NodeFilter-SHOW_PROCESSING_INSTRUCTION">SHOW_PROCESSING_INSTRUCTION</a> = 0x40;
  const unsigned long <a href="#dom-nodefilter-show_comment" title="dom-NodeFilter-SHOW_COMMENT">SHOW_COMMENT</a> = 0x80;
  const unsigned long <a href="#dom-nodefilter-show_document" title="dom-NodeFilter-SHOW_DOCUMENT">SHOW_DOCUMENT</a> = 0x100;
  const unsigned long <a href="#dom-nodefilter-show_document_type" title="dom-NodeFilter-SHOW_DOCUMENT_TYPE">SHOW_DOCUMENT_TYPE</a> = 0x200;
  const unsigned long <a href="#dom-nodefilter-show_document_fragment" title="dom-NodeFilter-SHOW_DOCUMENT_FRAGMENT">SHOW_DOCUMENT_FRAGMENT</a> = 0x400;
  const unsigned long <span title="dom-NodeFilter-SHOW_NOTATION">SHOW_NOTATION</span> = 0x800; // historical

  unsigned short <span title="dom-NodeFilter-acceptNode">acceptNode</span>(<a href="#node">Node</a> <var title="">node</var>);
};</pre>

<p><code><a href="#nodefilter">NodeFilter</a></code> objects can be used as
<a href="#concept-traversal-filter" title="concept-traversal-filter">filter</a> callback and provide
constants for the <a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a>
bitmask.

<p class="note">It is typically implemented as an ECMAScript function.

<p>These constants can be used as callback return value:

<ul class="brief">
 <li><dfn id="dom-nodefilter-filter_accept" title="dom-NodeFilter-FILTER_ACCEPT"><code>FILTER_ACCEPT</code></dfn> (1);
 <li><dfn id="dom-nodefilter-filter_reject" title="dom-NodeFilter-FILTER_REJECT"><code>FILTER_REJECT</code></dfn> (2);
 <li><dfn id="dom-nodefilter-filter_skip" title="dom-NodeFilter-FILTER_SKIP"><code>FILTER_SKIP</code></dfn> (3).
</ul>

<p>These constants can be used for the
<a href="#concept-traversal-whattoshow" title="concept-traversal-whatToShow">whatToShow</a> bitmask:

<ul class="brief">
 <li><dfn id="dom-nodefilter-show_all" title="dom-NodeFilter-SHOW_ALL"><code>SHOW_ALL</code></dfn> (4294967295, FFFFFFFF in hexadecimal);
 <li><dfn id="dom-nodefilter-show_element" title="dom-NodeFilter-SHOW_ELEMENT"><code>SHOW_ELEMENT</code></dfn> (1);
 <!-- AttrExodus
 <li><dfn title=dom-NodeFilter-SHOW_ATTRIBUTE><code>SHOW_ATTRIBUTE</code></dfn> (2, historical);
 -->
 <li><dfn id="dom-nodefilter-show_text" title="dom-NodeFilter-SHOW_TEXT"><code>SHOW_TEXT</code></dfn> (4);
 <!-- XXX still questionable
 <li><dfn title=dom-NodeFilter-SHOW_CDATA_SECTION><code>SHOW_CDATA_SECTION</code></dfn> (8; historical);
 -->
 <li><dfn id="dom-nodefilter-show_processing_instruction" title="dom-NodeFilter-SHOW_PROCESSING_INSTRUCTION"><code>SHOW_PROCESSING_INSTRUCTION</code></dfn> (64, 40 in hexadecimal);
 <li><dfn id="dom-nodefilter-show_comment" title="dom-NodeFilter-SHOW_COMMENT"><code>SHOW_COMMENT</code></dfn> (128, 80 in hexadecimal);
 <li><dfn id="dom-nodefilter-show_document" title="dom-NodeFilter-SHOW_DOCUMENT"><code>SHOW_DOCUMENT</code></dfn> (256, 100 in hexadecimal);
 <li><dfn id="dom-nodefilter-show_document_type" title="dom-NodeFilter-SHOW_DOCUMENT_TYPE"><code>SHOW_DOCUMENT_TYPE</code></dfn> (512, 200 in hexadecimal);
 <li><dfn id="dom-nodefilter-show_document_fragment" title="dom-NodeFilter-SHOW_DOCUMENT_FRAGMENT"><code>SHOW_DOCUMENT_FRAGMENT</code></dfn> (1024, 400 in hexadecimal).
</ul>



<h2 id="collections"><span class="secno">8 </span>Collections</h2>

<p>A <dfn id="concept-collection" title="concept-collection">collection</dfn> is an object that
represents a lists of DOM nodes. A
<a href="#concept-collection" title="concept-collection">collection</a> can be either
<dfn id="concept-collection-live" title="concept-collection-live">live</dfn> or
<dfn id="concept-collection-static" title="concept-collection-static">static</dfn>. Unless otherwise stated,
a <a href="#concept-collection" title="concept-collection">collection</a> must be
<a href="#concept-collection-live" title="concept-collection-live">live</a>.

<p>If a <a href="#concept-collection" title="concept-collection">collection</a> is <a href="#concept-collection-live" title="concept-collection-live">live</a>, then the attributes and methods
on that object must operate on the actual underlying data, not a snapshot of
the data.

<p>When a <a href="#concept-collection" title="concept-collection">collection</a> is created, a
filter and a root are associated with it.

<p>The <a href="#concept-collection" title="concept-collection">collection</a> then
<dfn id="represented-by-the-collection" title="represented by the collection">represents</dfn> a view of the
subtree rooted at the <a href="#concept-collection" title="concept-collection">collection's</a>
root, containing only nodes that match the given filter. The view is linear.
In the absence of specific requirements to the contrary, the nodes within
the <a href="#concept-collection" title="concept-collection">collection</a> must be sorted in
<a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

<p>An attribute that returns a
<a href="#concept-collection-live" title="concept-collection-live">live</a>
<a href="#concept-collection" title="concept-collection">collection</a> must return the same object
every time it is retrieved.


<h3 id="interface-nodelist"><span class="secno">8.1 </span>Interface <code><a href="#nodelist">NodeList</a></code></h3>
<p>A <code><a href="#nodelist">NodeList</a></code> object is a kind of
<a href="#concept-collection" title="concept-collection">collection</a>.

<pre class="idl">interface <dfn id="nodelist">NodeList</dfn> {
  getter <a href="#node">Node</a>? <a href="#dom-nodelist-item" title="dom-NodeList-item">item</a>(unsigned long index);
  readonly attribute unsigned long <a href="#dom-nodelist-length" title="dom-NodeList-length">length</a>;
};</pre>

<dl class="domintro">
 <dt><var title="">collection</var> . <code title="dom-NodeList-length"><a href="#dom-nodelist-length">length</a></code>
 <dd>
  <p>Returns the number of elements in the collection.

 <dt><var title="">element</var> = <var title="">collection</var> . <code title="dom-NodeList-item"><a href="#dom-nodelist-item">item</a></code>(<var title="">index</var>)
 <dt><var title="">element</var> = <var title="">collection</var>[<var title="">index</var>]
 <dd>
  <p>Returns the item with index <var title="">index</var> from the collection. The items are sorted in <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.
</dl>

<div class="impl">

<p>The object's <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>
are the numbers in the range zero to one less than the number of nodes
<a href="#represented-by-the-collection">represented by the collection</a>. If there are no such elements, then
there are no <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>.

<p>The <dfn id="dom-nodelist-length" title="dom-NodeList-length"><code>length</code></dfn> attribute must
return the number of nodes <a href="#represented-by-the-collection">represented by the collection</a>.

<p>The <dfn id="dom-nodelist-item" title="dom-NodeList-item"><code>item(<var title="">index</var>)</code></dfn> method must return the <var title="">index</var>th
node in the <a href="#concept-collection" title="concept-collection">collection</a>. If there is no
<var title="">index</var>th node in the <a href="#concept-collection" title="concept-collection">collection</a>, then the method must return null.

</div>


<h3 id="interface-htmlcollection"><span class="secno">8.2 </span>Interface <code><a href="#htmlcollection">HTMLCollection</a></code></h3>
<p>The <code><a href="#htmlcollection">HTMLCollection</a></code> interface represents a generic <a href="#concept-collection" title="concept-collection">collection</a> of
<a href="#concept-element" title="concept-element">elements</a>.

<p class="note">This interface is called <code><a href="#htmlcollection">HTMLCollection</a></code> for
historical reasons. The
<code title="dom-HTMLCollection-namedItem"><a href="#dom-htmlcollection-nameditem">namedItem</a></code> method returns an
<code class="external"><a href="http://dev.w3.org/2006/webapi/WebIDL/#idl-object">object</a></code> for interfaces that inherit from
this interface, which return other objects for historical reasons.

<pre class="idl">interface <dfn id="htmlcollection">HTMLCollection</dfn> {
  readonly attribute unsigned long <a href="#dom-htmlcollection-length" title="dom-HTMLCollection-length">length</a>;
  getter <a href="#element">Element</a>? <a href="#dom-htmlcollection-item" title="dom-HTMLCollection-item">item</a>(unsigned long index);
  getter object? <a href="#dom-htmlcollection-nameditem" title="dom-HTMLCollection-namedItem">namedItem</a>(DOMString name); // only returns <code><a href="#element">Element</a></code>
};</pre>

<dl class="domintro">
 <dt><var title="">collection</var> . <code title="dom-HTMLCollection-length"><a href="#dom-htmlcollection-length">length</a></code>
 <dd>
  <p>Returns the number of elements in the collection.

 <dt><var title="">element</var> = <var title="">collection</var> . <code title="dom-HTMLCollection-item"><a href="#dom-htmlcollection-item">item</a></code>(<var title="">index</var>)
 <dt><var title="">element</var> = <var title="">collection</var>[<var title="">index</var>]
 <dd>
  <p>Returns the item with index <var title="">index</var> from the collection. The items are sorted in <a href="#concept-tree-order" title="concept-tree-order">tree order</a>.

 <dt><var title="">element</var> = <var title="">collection</var> . <code title="dom-HTMLCollection-namedItem"><a href="#dom-htmlcollection-nameditem">namedItem</a></code>(<var title="">name</var>)
 <dt><var title="">element</var> = <var title="">collection</var>[<var title="">name</var>]
 <dd>
  <p>Returns the first item with <a href="#concept-id" title="concept-id">ID</a> or name <var title="">name</var>
  from the collection.
  <p>Only <code title="">a</code>, <code title="">applet</code>,
  <code title="">area</code>, <code title="">embed</code>,
  <code title="">form</code>, <code title="">frame</code>,
  <code title="">frameset</code>, <code title="">iframe</code>,
  <code title="">img</code>, and <code title="">object</code> elements in the
  <a href="#html-namespace">HTML namespace</a> can have a name for the purpose of this
  method; their name is given by the value of their
  <code title="">name</code> attribute.
</dl>

<div class="impl">

<p>The object's <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>
are the numbers in the range zero to one less than the number of nodes
<a href="#represented-by-the-collection">represented by the collection</a>. If there are no such elements, then
there are no <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>.

<p>The <dfn id="dom-htmlcollection-length" title="dom-HTMLCollection-length"><code>length</code></dfn> attribute
must return the number of nodes <a href="#represented-by-the-collection">represented by the collection</a>.

<p>The <dfn id="dom-htmlcollection-item" title="dom-HTMLCollection-item"><code>item(<var title="">index</var>)</code></dfn> method must return the <var title="">index</var>th node in the collection. If there is no <var title="">index</var>th node in the collection, then the method must
return null.

<p>The <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-names">supported property names</a> consist
of the values of the <code title="">name</code> attributes of each <code title="">a</code>, <code title="">applet</code>, <code title="">area</code>, <code title="">embed</code>, <code title="">form</code>, <code title="">frame</code>, <code title="">frameset</code>, <code title="">iframe</code>, <code title="">img</code>, and
<code title="">object</code> element in the <a href="#html-namespace">HTML namespace</a>,
<a href="#represented-by-the-collection">represented by the collection</a> with a <code title="">name</code>
attribute, plus the list of <a href="#concept-id" title="concept-id">IDs</a> that the elements
<a href="#represented-by-the-collection">represented by the collection</a> have.

<p>The
<dfn id="dom-htmlcollection-nameditem" title="dom-HTMLCollection-namedItem"><code>namedItem(<var title="">key</var>)</code></dfn>
method must return the first <a href="#concept-element" title="concept-element">element</a> in
the <a href="#concept-collection" title="concept-collection">collection</a> that falls into one of
the following categories:

<ul>
 <li>It is an <code title="">a</code>, <code title="">applet</code>, <code title="">area</code>, <code title="">embed</code>, <code title="">form</code>, <code title="">frame</code>, <code title="">frameset</code>, <code title="">iframe</code>,
 <code title="">img</code>, or <code title="">object</code>
 <a href="#concept-element" title="concept-element">element</a>, in the
 <a href="#html-namespace">HTML namespace</a>, with a <code title="">name</code>
 <a href="#concept-attribute" title="concept-attribute">attribute</a> equal to
 <var title="">key</var>, or,

 <li>It is an <a href="#concept-element" title="concept-element">element</a> with an
 <a href="#concept-id" title="concept-id">ID</a> equal to <var title="">key</var>.
</ul>

<p>If no such <a href="#concept-element" title="concept-element">elements</a> are found, then
the method must return null.

</div>


<!-- AttrExodus
<h3>Interface <code>NamedNodeMap</code></h3>
<p>Since <code title=dom-Node-attributes>attributes</code> is the
only remaining API using this interface and the tentative plan is to change
<code>Attr</code> we also plan to remove this interface and replace it with
a lightweight <code>AttrMap</code> or some such &mdash;
<a href=http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html>http://lists.w3.org/Archives/Public/public-webapps/2010JulSep/0797.html</a>

<p>A <code>NamedNodeMap</code> object is a kind of <span
title=concept-collection>collection</span>, whose primary purpose is to expose
<code>Node</code>s by name.

<pre class=idl>interface <dfn>NamedNodeMap</dfn> {
  <span>Node</span> <span title=dom-NamedNodeMap-getNamedItem>getNamedItem</span>(DOMString name);
  <span>Node</span> <span title=dom-NamedNodeMap-setNamedItem>setNamedItem</span>(<span>Node</span> arg);
  <span>Node</span> <span title=dom-NamedNodeMap-removeNamedItem>removeNamedItem</span>(DOMString name);
  <span>Node</span> <span title=dom-NamedNodeMap-item>item</span>(unsigned long index);
  readonly attribute unsigned long <span title=dom-NamedNodeMap-length>length</span>;
  <span>Node</span> <span title=dom-NamedNodeMap-getNamedItemNS>getNamedItemNS</span>(DOMString namespace, DOMString localName);
  <span>Node</span> <span title=dom-NamedNodeMap-setNamedItemNS>setNamedItemNS</span>(<span>Node</span> arg);
  <span>Node</span> <span title=dom-NamedNodeMap-removeNamedItemNS>removeNamedItemNS</span>(DOMString namespace, DOMString localName);
};</pre>

<p><dfn title=dom-NamedNodeMap-getNamedItem>getNamedItem</dfn>

<p><dfn title=dom-NamedNodeMap-setNamedItem>setNamedItem</dfn>

<p><dfn title=dom-NamedNodeMap-removeNamedItem>removeNamedItem</dfn>

<p><dfn title=dom-NamedNodeMap-item>item</dfn>

<p>The <dfn title=dom-NamedNodeMap-length><code>length</code></dfn> attribute must return the number of nodes <span>represented by the collection</span>.

<p><dfn title=dom-NamedNodeMap-getNamedItemNS>getNamedItemNS</dfn>

<p><dfn title=dom-NamedNodeMap-setNamedItemNS>setNamedItemNS</dfn>

<p><dfn title=dom-NamedNodeMap-removeNamedItemNS>removeNamedItemNS</dfn>
-->


<h2 id="lists"><span class="secno">9 </span>Lists</h2>

<h3 id="interface-domstringlist"><span class="secno">9.1 </span>Interface <code><a href="#domstringlist">DOMStringList</a></code></h3>

<!--
 HTMLPropertiesCollection.names
 DataTranser.types
 Clipboard.types
 Document.styleSheetSets
 IndexedDB APIs
-->

<pre class="idl">interface <dfn id="domstringlist">DOMStringList</dfn> {
  readonly attribute unsigned long <a href="#dom-domstringlist-length" title="dom-DOMStringList-length">length</a>;
  getter DOMString? <a href="#dom-domstringlist-item" title="dom-DOMStringList-item">item</a>(unsigned long <var title="">index</var>);
  boolean <a href="#dom-domstringlist-contains" title="dom-DOMStringList-contains">contains</a>(DOMString <var title="">string</var>);
};</pre>

<p>The <code><a href="#domstringlist">DOMStringList</a></code> interface represents an interface to an
ordered list of strings.

<dl class="domintro">
 <dt><var title="">stringlist</var> . <code title="dom-DOMStringList-length"><a href="#dom-domstringlist-length">length</a></code>
 <dd><p>Returns the number of tokens in the string.

 <dt><var title="">string</var> = <var title="">stringlist</var> . <code title="dom-DOMStringList-item"><a href="#dom-domstringlist-item">item</a></code>(<var title="">index</var>)
 <dt><var title="">stringlist</var>[<var title="">index</var>]
 <dd>
  <p>Returns the string with index <var title="">index</var>.

 <dt><var title="">hasstring</var> = <var title="">stringlist</var> . <code title="dom-DOMStringList-contains"><a href="#dom-domstringlist-contains">contains</a></code>(<var title="">string</var>)
 <dd><p>Returns true if the <var title="">string</var> is present; false
 otherwise.
</dl>

<div class="impl">

<p>The <dfn id="dom-domstringlist-length" title="dom-DOMStringList-length"><code>length</code></dfn>
attribute must return the number of strings in the list.

<p>The object's
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a> are the
numbers in the range zero to the <a href="#context-object">context object</a>'s
<code title="dom-DOMStringList-length"><a href="#dom-domstringlist-length">length</a></code> attribute value minus 1,
unless the <a href="#context-object">context object</a>'s
<code title="dom-DOMStringList-length"><a href="#dom-domstringlist-length">length</a></code> attribute  value is zero,
in which case there are no
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>.

<p>The
<dfn id="dom-domstringlist-item" title="dom-DOMStringList-item"><code>item(<var title="">index</var>)</code></dfn>
method must return the <var title="">index</var>th string in the list. If
<var title="">index</var> is equal to or greater than the number of strings, then the
method must return null.

<p>The
<dfn id="dom-domstringlist-contains" title="dom-DOMStringList-contains"><code>contains(<var title="">string</var>)</code></dfn>
method must return true if the list of strings contains <var title="">string</var>,
or false otherwise.

</div>


<h3 id="interface-domtokenlist"><span class="secno">9.2 </span>Interface <code><a href="#domtokenlist">DOMTokenList</a></code></h3>
<p>The <code><a href="#domtokenlist">DOMTokenList</a></code> interface represents an interface to an
<dfn id="concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</dfn> that
consists of a <a href="#set-of-space-separated-tokens">set of space-separated tokens</a>.

<p class="note"><code><a href="#domtokenlist">DOMTokenList</a></code> objects are always
<a href="#case-sensitive">case-sensitive</a>, even when the underlying string might
ordinarily be treated in a case-insensitive manner.

<pre class="idl">interface <dfn id="domtokenlist">DOMTokenList</dfn> {
  readonly attribute unsigned long <a href="#dom-domtokenlist-length" title="dom-DOMTokenList-length">length</a>;
  getter DOMString? <a href="#dom-domtokenlist-item" title="dom-DOMTokenList-item">item</a>(unsigned long index);
  boolean <a href="#dom-domtokenlist-contains" title="dom-DOMTokenList-contains">contains</a>(DOMString token);
  void <a href="#dom-domtokenlist-add" title="dom-DOMTokenList-add">add</a>(DOMString token);
  void <a href="#dom-domtokenlist-remove" title="dom-DOMTokenList-remove">remove</a>(DOMString token);
  boolean <a href="#dom-domtokenlist-toggle" title="dom-DOMTokenList-toggle">toggle</a>(DOMString token);
  <a href="#dom-domtokenlist-tostring" title="dom-DOMTokenList-toString">stringifier</a> DOMString ();
};</pre>

<dl class="domintro">
 <dt><var title="">tokenlist</var> . <code title="dom-DOMTokenList-length"><a href="#dom-domtokenlist-length">length</a></code>
 <dd>
  <p>Returns the number of tokens in the string.

 <dt><var title="">element</var> = <var title="">tokenlist</var> . <code title="dom-DOMTokenList-item"><a href="#dom-domtokenlist-item">item</a></code>(<var title="">index</var>)
 <dt><var title="">tokenlist</var>[<var title="">index</var>]
 <dd>
  <p>Returns the token with index <var title="">index</var>. The tokens are returned in the order they are found in the underlying string.

 <dt><var title="">hastoken</var> = <var title="">tokenlist</var> . <code title="dom-DOMTokenList-contains"><a href="#dom-domtokenlist-contains">contains</a></code>(<var title="">token</var>)
 <dd>
  <p>Returns true if the <var title="">token</var> is present; false otherwise.
  <p>Throws a "<code><a href="#syntaxerror">SyntaxError</a></code>" exception if <var title="">token</var> is empty.
  <p>Throws an "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception if <var title="">token</var> contains any spaces.

 <dt><var title="">tokenlist</var> . <code title="dom-DOMTokenList-add"><a href="#dom-domtokenlist-add">add</a></code>(<var title="">token</var>)
 <dd>
  <p>Adds <var title="">token</var>, unless it is already present.
  <p>Throws a "<code><a href="#syntaxerror">SyntaxError</a></code>" exception if <var title="">token</var> is empty.
  <p>Throws an "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception if <var title="">token</var> contains any spaces.

 <dt><var title="">tokenlist</var> . <code title="dom-DOMTokenList-remove"><a href="#dom-domtokenlist-remove">remove</a></code>(<var title="">token</var>)
 <dd>
  <p>Removes <var title="">token</var> if it is present.
  <p>Throws a "<code><a href="#syntaxerror">SyntaxError</a></code>" exception if <var title="">token</var> is empty.
  <p>Throws an "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception if <var title="">token</var> contains any spaces.

 <dt><var title="">hastoken</var> = <var title="">tokenlist</var> . <code title="dom-DOMTokenList-toggle"><a href="#dom-domtokenlist-toggle">toggle</a></code>(<var title="">token</var>)
 <dd>
  <p>Adds <var title="">token</var> if it is not present, or removes
  it if it is. Returns true if <var title="">token</var> is now
  present (it was added); returns false if it is not (it was
  removed).
  <p>Throws a "<code><a href="#syntaxerror">SyntaxError</a></code>" exception if <var title="">token</var> is empty.
  <p>Throws an "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception if <var title="">token</var> contains any spaces.
</dl>

<div class="impl">

<p>The <dfn id="dom-domtokenlist-length" title="dom-DOMTokenList-length"><code>length</code></dfn>
attribute must return the number of tokens that result from
<a href="#split-a-string-on-spaces" title="split a string on spaces">splitting</a> the
<a href="#context-object">context object</a>'s
<a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> on
spaces.

<p>The object's
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a> are the
numbers in the range zero to the <a href="#context-object">context object</a>'s
<code title="dom-DOMTokenList-length"><a href="#dom-domtokenlist-length">length</a></code> attribute value minus 1,
unless the <a href="#context-object">context object</a>'s
<code title="dom-DOMTokenList-length"><a href="#dom-domtokenlist-length">length</a></code> attribute value is zero,
in which case there are no
<a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-supported-property-indices">supported property indices</a>.

<p>The
<dfn id="dom-domtokenlist-item" title="dom-DOMTokenList-item"><code>item(<var title="">index</var>)</code></dfn>
method must run these steps:

<ol>
 <li>If <var title="">index</var> is equal to or greater than the
 <a href="#context-object">context object</a>'s
 <code title="dom-DOMTokenList-length"><a href="#dom-domtokenlist-length">length</a></code> attribute value, then
 return null and terminate these steps.

 <li><a href="#split-a-string-on-spaces" title="split a string on spaces">Split</a> the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> on
 spaces, preserving the order of the tokens as found in the
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>,
 to get the list of tokens.

 <li>Return the <var title="">index</var>th item in this list.
</ol>

<p class="example">For example, if the string is "<code title="">a b a c</code>"
then there are four tokens: the token with index 0 is "<code title="">a</code>",
the token with index 1 is "<code title="">b</code>", the token with index 2 is
"<code title="">a</code>", and the token with index 3 is "<code title="">c</code>".

<p>The
<dfn id="dom-domtokenlist-contains" title="dom-DOMTokenList-contains"><code>contains(<var title="">token</var>)</code></dfn>
method must run these steps:

<ol>
 <li>If <var title="">token</var> is the empty string, then
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#syntaxerror">SyntaxError</a></code>" exception and terminate these steps.

 <li>If <var title="">token</var> contains any
 <a href="#space-character" title="space character">space characters</a>, then
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><a href="#split-a-string-on-spaces" title="split a string on spaces">Split</a> the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> on
 spaces to get the list of tokens.

 <li>Return true if <var title="">token</var> is a <a href="#case-sensitive">case-sensitive</a>
 match for one of the tokens in the list found in the previous step, or
 false otherwise.
</ol>

<p>The
<dfn id="dom-domtokenlist-add" title="dom-DOMTokenList-add"><code>add(<var title="">token</var>)</code></dfn>
method must run these steps:

<ol>
 <li>If <var title="">token</var> is the empty string, then
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#syntaxerror">SyntaxError</a></code>" exception and terminate these steps.

 <li>If <var title="">token</var> contains any
 <a href="#space-character" title="space character">space characters</a>, then
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><a href="#split-a-string-on-spaces" title="split a string on spaces">Split</a> the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> on
 spaces to get the list of tokens.

 <li>If <var title="">token</var> is a <a href="#case-sensitive">case-sensitive</a> match for one of
 the tokens in the list found in the previous step, then terminate these steps.

 <li>If the <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> is not
 the empty string and the last character of that string is not a
 <a href="#space-character">space character</a>, then append a U+0020 SPACE character to that
 string.

 <li>Append <var title="">token</var> to the <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>.
</ol>

<p>The
<dfn id="dom-domtokenlist-remove" title="dom-DOMTokenList-remove"><code>remove(<var title="">token</var>)</code></dfn>
method must run these steps:

<ol>
 <li>If <var title="">token</var> is the empty string, then
 <a href="#concept-throw" title="concept-throw">throw</a> a
 "<code><a href="#syntaxerror">SyntaxError</a></code>" exception and terminate these steps.

 <li>If <var title="">token</var> contains any
 <a href="#space-character" title="space character">space characters</a>, then
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><a href="#remove-a-token-from-a-string" title="remove a token from a string">Remove</a>
 <var title="">token</var> from  the <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>.
</ol>

<p>The
<dfn id="dom-domtokenlist-toggle" title="dom-DOMTokenList-toggle"><code>toggle(<var title="">token</var>)</code></dfn>
method must run these steps:

<ol>
 <li>If <var title="">token</var> is the empty string, then
 <a href="#concept-throw" title="concept-throw">throw</a> a "<code><a href="#syntaxerror">SyntaxError</a></code>"
 exception and terminate these steps.

 <li>If <var title="">token</var> contains any
 <a href="#space-character" title="space character">space characters</a>, then
 <a href="#concept-throw" title="concept-throw">throw</a> an
 "<code><a href="#invalidcharactererror">InvalidCharacterError</a></code>" exception and terminate these
 steps.

 <li><a href="#split-a-string-on-spaces" title="split a string on spaces">Split</a> the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> on
 spaces to get the list of tokens.

 <li>If <var title="">token</var> is a <a href="#case-sensitive">case-sensitive</a> match for one of
 the tokens in the list found in the previous step, then
 <a href="#remove-a-token-from-a-string" title="remove a token from a string">remove</a>
 <var title="">token</var> from  the <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>,
 return false and terminate these steps.

 <li>If the <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a> is
 not the empty string and the last character of that string is not a
 <a href="#space-character">space character</a>, then append a U+0020 SPACE character to that
 string.

 <li>Append the value of <var title="">token</var> to the
 <a href="#context-object">context object</a>'s
 <a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>.

 <li>Return true.
</ol>

<p><code><a href="#domtokenlist">DOMTokenList</a></code> objects must
<dfn id="dom-domtokenlist-tostring" title="dom-DOMTokenList-toString">stringify</dfn> to the
<a href="#context-object">context object</a>'s
<a href="#concept-tokenlist-underlying-string" title="concept-tokenlist-underlying-string">underlying string</a>.

</div>


<h3 id="interface-domsettabletokenlist"><span class="secno">9.3 </span>Interface <code><a href="#domsettabletokenlist">DOMSettableTokenList</a></code></h3>

<p>The <code><a href="#domsettabletokenlist">DOMSettableTokenList</a></code> interface is the same as the
<code><a href="#domtokenlist">DOMTokenList</a></code> interface, except that it allows the
underlying string to be directly changed.

<pre class="idl">interface <dfn id="domsettabletokenlist">DOMSettableTokenList</dfn> : <a href="#domtokenlist">DOMTokenList</a> {
            attribute DOMString <a href="#dom-domsettabletokenlist-value" title="dom-DOMSettableTokenList-value">value</a>;
};</pre>

<dl class="domintro">
 <dt><var title="">tokenlist</var> . <code title="dom-DOMSettableTokenList-value"><a href="#dom-domsettabletokenlist-value">value</a></code>
 <dd>
  <p>Returns the underlying string.
  <p>Can be set, to change the underlying string.
</dl>

<div class="impl">

<p>An object implementing the <code><a href="#domsettabletokenlist">DOMSettableTokenList</a></code>
interface must act as defined for the <code><a href="#domtokenlist">DOMTokenList</a></code>
interface, except for the <code title="dom-DOMSettableTokenList-value"><a href="#dom-domsettabletokenlist-value">value</a></code> attribute defined
here.

<p>The <dfn id="dom-domsettabletokenlist-value" title="dom-DOMSettableTokenList-value"><code>value</code></dfn>
attribute must return the underlying string and, on setting must replace the underlying string with the new value.

</div>



<h2 id="dom-features"><span class="secno">10 </span>DOM features</h2>
<p class="warning">Authors are strongly discouraged from using
<a href="#concept-domfeature" title="concept-DOMfeature">DOM features</a>, as they are notoriously
unreliable and imprecise. Authors are encouraged to rely on explicit feature
testing or graceful degradation.

<p>A <dfn id="concept-domfeature" title="concept-DOMfeature">DOM feature</dfn> is a unique,
<a href="#ascii-case-insensitive">ASCII case-insensitive</a> string that represents a certain feature of
the user agent.

<p>A <dfn id="concept-domfeatureversion" title="concept-DOMfeatureversion">DOM feature version</dfn> is a (<var title="">feature</var>,&nbsp;<var title="">version</var>) tuple, where <var title="">feature</var> is <a href="#concept-domfeature" title="concept-DOMfeature">DOM feature</a>
and <var title="">version</var> is a <a href="#case-sensitive">case-sensitive</a> string
representing a version number.
<!--of the form "<var title>major</var>.<var title>minor</var>".-->

<p>Specifications may define which <a href="#concept-domfeature" title="concept-DOMfeature">DOM
features</a> a user agent is to <dfn id="concept-support-domfeature" title="concept-support-DOMfeature">support</dfn>, as well as an associated list of
one or more <a href="#case-sensitive">case-sensitive</a> strings representing version numbers, and under which circumstances, when necessary for compatibility (i.e. because of historical use). Specifications must not introduce new <a href="#concept-domfeature" title="concept-DOMfeature">DOM
features</a> or new versions for existing features.

<div class="impl">

<p>A user agent must <dfn id="concept-support-domfeatureversion" title="concept-support-DOMfeatureversion">support</dfn>
a <a href="#concept-domfeatureversion" title="concept-DOMfeatureversion">DOM feature version</a> (<var title="">feature</var>,&nbsp;<var title="">version</var>) if it <a href="#concept-support-domfeature" title="concept-support-DOMfeature">supports</a> a <a href="#concept-domfeature" title="concept-DOMfeature">DOM feature</a> that is a <a href="#ascii-case-insensitive">ASCII
case-insensitive</a> match for <var title="">feature</var> and <var title="">version</var> is in the associated list of versions.

<p>A user agent must <a href="#concept-support-domfeatureversion" title="concept-support-DOMfeatureversion">support</a> the (<var title="">feature</var>,&nbsp;"") tuple if it <a href="#concept-support-domfeature" title="concept-support-DOMfeature">supports</a> a <a href="#concept-domfeature" title="concept-DOMfeature">DOM feature</a> that is a <a href="#ascii-case-insensitive">ASCII
case-insensitive</a> match for <var title="">feature</var>.

<p>For historical reasons, user agents must <a href="#concept-support-domfeatureversion" title="concept-support-DOMfeatureversion">support</a> the
"XML" <a href="#concept-domfeature" title="concept-DOMfeature">DOM feature</a> with the versions "1.0"
and "2.0" associated with it, and the "Core" <a href="#concept-domfeature" title="concept-DOMfeature">DOM
feature</a> with the version "2.0" associated with it.

<!-- Chrome supports Core/1.0; Opera supports x/undefined -->

</div>



<h2 id="historical"><span class="secno">11 </span>Historical</h2>

<!-- XXX we should probably just nuke this section in due course. No need to keep old dreams alive. -->

<p>As explained in <a href="#goals">goals</a> this specification is a
significant revision of various DOM specifications. This section attempts to
enumerate the changes.


<h3 id="dom-events"><span class="secno">11.1 </span>DOM Events</h3>

<p>These are the changes made to the features described in the
"DOM Event Architecture" and "Basic Event Interfaces" chapters of
<cite>DOM Level 3 Events</cite>. The other chapters are expected to move to
a separate specification.

<ul class="brief">
 <li>Events have constructors now.
 <li>No more restrictions on <code title="dom-Event-type"><a href="#dom-event-type">Event.type</a></code>.
 <li><code title="dom-Event-preventDefault"><a href="#dom-event-preventdefault">preventDefault()</a></code> only
 changes what <code title="dom-Event-defaultPrevented"><a href="#dom-event-defaultprevented">defaultPrevented</a></code>
 and <code title="dom-EventTarget-dispatchEvent"><a href="#dom-eventtarget-dispatchevent">dispatchEvent()</a></code> return
 if the event is cancelable.
 <li>Removes <dfn id="eventexception"><code>EventException</code></dfn>.
 <li>Fire is no longer synonymous with dispatch, but includes initializing
 an event.</li>
 <li>The propagation and canceled flags are unset when invoking
 <code title="dom-Event-initEvent"><a href="#dom-event-initevent">initEvent()</a></code> rather than after
 dispatch.
</ul>


<h3 id="dom-core"><span class="secno">11.2 </span>DOM Core</h3>

<p>These are the changes made to the features described in
<cite>DOM Level 3 Core</cite>.

<p><dfn id="domstring"><code>DOMString</code></dfn> and
<dfn id="domtimestamp"><code>DOMTimeStamp</code></dfn> are now defined in Web IDL.

<p><code><a href="#node">Node</a></code> now inherits from <code><a href="#eventtarget">EventTarget</a></code>.</p>

<p><a href="#concept-node" title="concept-node">Nodes</a> are implicitly
<a href="#concept-node-adopt" title="concept-node-adopt">adopted</a> across
<a href="#concept-document" title="concept-document">document</a> boundaries.

<p><a href="#concept-doctype" title="concept-doctype">Doctypes</a> now always have a
<a href="#concept-node-document" title="concept-node-document">node document</a> and can be moved
across <a href="#concept-document" title="concept-document">document</a> boundaries.

<p><code><a href="#processinginstruction">ProcessingInstruction</a></code> now inherits from
<code><a href="#characterdata">CharacterData</a></code>.

<p><code><a href="#domerror">DOMError</a></code> is completely redesigned.</p>

<p>The remainder of interfaces and interface members listed in this section
were removed to simplify the DOM platform. Implementations conforming to
this specification will not support them.

<p>Interfaces:
<ul class="brief">
 <li><dfn id="cdatasection"><code>CDATASection</code></dfn>
 <li><dfn id="domconfiguration"><code>DOMConfiguration</code></dfn>
 <li><dfn id="domerrorhandler"><code>DOMErrorHandler</code></dfn>
 <li><dfn id="domimplementationlist"><code>DOMImplementationList</code></dfn>
 <li><dfn id="domimplementationsource"><code>DOMImplementationSource</code></dfn>
 <li><dfn id="domlocator"><code>DOMLocator</code></dfn>
 <li><dfn id="domobject"><code>DOMObject</code></dfn>
 <li><dfn id="domuserdata"><code>DOMUserData</code></dfn>
 <li><dfn id="entity"><code>Entity</code></dfn>
 <li><dfn id="entityreference"><code>EntityReference</code></dfn>
 <li><dfn id="namednodemap"><code>NamedNodeMap</code></dfn> <!--AttrExodus-->
 <li><dfn id="namelist"><code>NameList</code></dfn>
 <li><dfn id="notation"><code>Notation</code></dfn>
 <li><dfn id="typeinfo"><code>TypeInfo</code></dfn>
 <li><dfn id="userdatahandler"><code>UserDataHandler</code></dfn>
</ul>

<p>Interface members:
<dl>
 <dt><code><a href="#node">Node</a></code>
 <dd>
  <ul class="brief">
   <!--AttrExodus-->
   <li><dfn id="dom-node-hasattributes" title="dom-Node-hasAttributes"><code>hasAttributes()</code></dfn>
   <li><dfn id="dom-node-attributes" title="dom-Node-attributes"><code>attributes</code></dfn>

   <!--NodeExodus-->
   <li><dfn id="dom-node-namespaceuri" title="dom-Node-namespaceURI"><code>namespaceURI</code></dfn>
   <li><dfn id="dom-node-prefix" title="dom-Node-prefix"><code>prefix</code></dfn>
   <li><dfn id="dom-node-localname" title="dom-Node-localName"><code>localName</code></dfn>

   <li><dfn id="dom-node-issupported" title="dom-Node-isSupported"><code>isSupported</code></dfn>
   <li><dfn id="dom-node-getfeature" title="dom-Node-getFeature"><code>getFeature()</code></dfn>
   <li><dfn id="dom-node-getuserdata" title="dom-Node-getUserData"><code>getUserData()</code></dfn>
   <li><dfn id="dom-node-setuserdata" title="dom-Node-setUserData"><code>setUserData()</code></dfn>

   <li><dfn id="dom-node-issamenode" title="dom-Node-isSameNode"><code>isSameNode()</code></dfn>
  </ul>

 <dt><code><a href="#document">Document</a></code>
 <dd>
  <ul class="brief">
   <li><dfn id="dom-document-createcdatasection" title="dom-Document-createCDATASection"><code>createCDATASection()</code></dfn>
   <li><dfn id="dom-document-createattribute" title="dom-Document-createAttribute"><code>createAttribute()</code></dfn>
   <li><dfn id="dom-document-createattributens" title="dom-Document-createAttributeNS"><code>createAttributeNS()</code></dfn>
   <li><dfn id="dom-document-createentityreference" title="dom-Document-createEntityReference"><code>createEntityReference()</code></dfn>
   <li><dfn id="dom-document-inputencoding" title="dom-Document-inputEncoding"><code>inputEncoding</code></dfn>
   <li><dfn id="dom-document-xmlencoding" title="dom-Document-xmlEncoding"><code>xmlEncoding</code></dfn>
   <li><dfn id="dom-document-xmlstandalone" title="dom-Document-xmlStandalone"><code>xmlStandalone</code></dfn>
   <li><dfn id="dom-document-xmlversion" title="dom-Document-xmlVersion"><code>xmlVersion</code></dfn>
   <li><dfn id="dom-document-stricterrorchecking" title="dom-Document-strictErrorChecking"><code>strictErrorChecking</code></dfn>
   <li><dfn id="dom-document-domconfig" title="dom-Document-domConfig"><code>domConfig</code></dfn>
   <li><dfn id="dom-document-normalizedocument" title="dom-Document-normalizeDocument"><code>normalizeDocument()</code></dfn>
   <li><dfn id="dom-document-renamenode" title="dom-Document-renameNode"><code>renameNode()</code></dfn>
  </ul>

 <dt><code><a href="#domimplementation">DOMImplementation</a></code>
 <dd>
  <ul class="brief">
   <li><dfn id="dom-domimplementation-getfeature" title="dom-DOMImplementation-getFeature"><code>getFeature()</code></dfn>
  </ul>

 <dt><code><a href="#attr">Attr</a></code>
 <dd>
  <p>No longer inherits from <code><a href="#node">Node</a></code> and therefore completely
  changed.
  <!--AttrExodus
  <p><dfn title=dom-Attr-schemaTypeInfo><code>schemaTypeInfo</code></dfn>
  <p><dfn title=dom-Attr-isId><code>isId</code></dfn>
  -->

 <dt><code><a href="#element">Element</a></code>
 <dd>
  <ul class="brief">
   <li><dfn id="dom-element-getattributenode" title="dom-Element-getAttributeNode"><code>getAttributeNode()</code></dfn>
   <li><dfn id="dom-element-getattributenodens" title="dom-Element-getAttributeNodeNS"><code>getAttributeNodeNS()</code></dfn>
   <li><dfn id="dom-element-setattributenode" title="dom-Element-setAttributeNode"><code>setAttributeNode()</code></dfn>
   <li><dfn id="dom-element-removeattributenode" title="dom-Element-removeAttributeNode"><code>removeAttributeNode()</code></dfn>
   <li><dfn id="dom-element-schematypeinfo" title="dom-Element-schemaTypeInfo"><code>schemaTypeInfo</code></dfn>
   <li><dfn id="dom-element-setidattribute" title="dom-Element-setIdAttribute"><code>setIdAttribute()</code></dfn>
   <li><dfn id="dom-element-setidattributens" title="dom-Element-setIdAttributeNS"><code>setIdAttributeNS()</code></dfn>
   <li><dfn id="dom-element-setidattributenode" title="dom-Element-setIdAttributeNode"><code>setIdAttributeNode()</code></dfn>
  </ul>

 <dt><code><a href="#documenttype">DocumentType</a></code>
 <dd>
  <ul class="brief">
   <li><dfn id="dom-documenttype-entities" title="dom-DocumentType-entities"><code>entities</code></dfn>
   <li><dfn id="dom-documenttype-notations" title="dom-DocumentType-notations"><code>notations</code></dfn>
   <li><dfn id="dom-documenttype-internalsubset" title="dom-DocumentType-internalSubset"><code>internalSubset</code></dfn>
  </ul>

 <dt><code><a href="#text">Text</a></code>
 <dd>
  <ul class="brief">
   <li><dfn id="dom-text-iselementcontentwhitespace" title="dom-Text-isElementContentWhitespace"><code>isElementContentWhitespace</code></dfn>
   <li><dfn id="dom-text-replacewholetext" title="dom-Text-replaceWholeText"><code>replaceWholeText()</code></dfn>
  </ul>
</dl>

<h3 id="dom-range"><span class="secno">11.3 </span>DOM Range</h3>

<p>These are the changes made to the features described in the
"Document Object Model Range" chapter of
<cite>DOM Level 2 Traversal and Range</cite>.

<p><dfn id="rangeexception"><code>RangeException</code></dfn> has been removed.

<p><code><a href="#range">Range</a></code> objects can now be moved between
<a href="#concept-document" title="concept-document">documents</a> and used on
<a href="#concept-node" title="concept-node">nodes</a> that are not
<a href="#in-a-document">in a document</a>.

<p class="XXX">Probably incomplete.


<h3 id="dom-traversal"><span class="secno">11.4 </span>DOM Traversal</h3>

<p>These are the changes made to the features described in the
"Document Object Model Traversal" chapter of
<cite>DOM Level 2 Traversal and Range</cite>.

<p>Differences with respect to
<code title="dom-Document-createNodeIterator"><a href="#dom-document-createnodeiterator">createNodeIterator()</a></code> and
<code title="dom-Document-createTreeWalker"><a href="#dom-document-createtreewalker">createTreeWalker()</a></code>:</p>

<ul>
 <li><p>In the previous edition of DOM Traversal both these methods accepted
 a fourth argument named <var title="">entityReferenceExpansion</var> that has
 been dropped as the DOM never actually exposed entity references in
 practice.

 <li><p>In the previous edition of DOM Traversal both these methods threw a
 "<code><a href="#notsupportederror">NotSupportedError</a></code>" when the <var title="">root</var> was
 null. Now this will throw a language-binding specific exception.

 <li><p>In the previous edition of DOM Traversal both these methods did not
 have optional arguments. That was changed for convenience.
</ul>

<p><code title="dom-NodeFilter-acceptNode">acceptNode()</code> and its
constants have been changed to use unsigned short, rather than just short.

<p>The <code title="">expandEntityReferences</code> attribute has been removed
from the <code><a href="#nodeiterator">NodeIterator</a></code> and <code><a href="#treewalker">TreeWalker</a></code> objects.

<p>The <code title="dom-NodeIterator-referenceNode"><a href="#dom-nodeiterator-referencenode">referenceNode</a></code> and
<code title="dom-NodeIterator-pointerBeforeReferenceNode"><a href="#dom-nodeiterator-pointerbeforereferencenode">pointerBeforeReferenceNode</a></code>
attributes have been added to <code><a href="#nodeiterator">NodeIterator</a></code> objects to align
with user agents.

<p><code title="dom-NodeIterator-nextNode"><a href="#dom-nodeiterator-nextnode">nextNode()</a></code> and
<code title="dom-NodeIterator-previousNode"><a href="#dom-nodeiterator-previousnode">previousNode()</a></code> node now
throw when invoked from a <code><a href="#nodefilter">NodeFilter</a></code> to align with user agents.


<h2 class="no-num" id="references">References</h2>
<div class="w3conly">
<h3 class="no-num" id="normative-references">Normative references</h3>
<div id="anolis-references-normative"><dl><dt id="refsIANACHARSET">[IANACHARSET]
<dd><cite><a href="http://www.iana.org/assignments/character-sets">Character Sets</a></cite>. IANA.

<dt id="refsRFC2119">[RFC2119]
<dd><cite><a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a></cite>, Scott Bradner. IETF.

<dt id="refsWEBIDL">[WEBIDL]
<dd><cite><a href="http://dev.w3.org/2006/webapi/WebIDL/">Web IDL</a></cite>, Cameron McCormack. W3C.

<dt id="refsXML">[XML]
<dd><cite><a href="http://www.w3.org/TR/xml/">Extensible Markup Language</a></cite>, Tim Bray, Jean Paoli, C. M. Sperberg-McQueen et al.. W3C.

<dt id="refsXMLNS">[XMLNS]
<dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in XML</a></cite>, Tim Bray, Dave Hollander, Andrew Layman et al.. W3C.

</dl></div>

<h3 class="no-num" id="informative-references">Informative references</h3>
<div id="anolis-references-informative"><dl><dt id="refsCSSOMVIEW">[CSSOMVIEW]
<dd><cite><a href="http://dev.w3.org/csswg/cssom-view/">CSSOM View</a></cite>, Anne van Kesteren. W3C.

<dt id="refsDOM2TR">[DOM2TR]
<dd><cite><a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/">Document Object Model (DOM) Level 2 Traversal and Range Specification</a></cite>, Joe Kesselman, Jonathan Robie, Mike Champion et al.. W3C.

<dt id="refsDOM3CORE">[DOM3CORE]
<dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Core/">Document Object Model (DOM) Level 3 Core Specification</a></cite>, Arnaud Le Hors, Philippe Le H&eacute;garet, Lauren Wood et al.. W3C.

<dt id="refsDOM3EVENTS">[DOM3EVENTS]
<dd><cite><a href="http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html">Document Object Model (DOM) Level 3 Events Specification</a></cite>, Doug Schepers and Jacob Rossi. W3C.

<dt id="refsDOMPS">[DOMPS]
<dd><cite><a href="http://html5.org/specs/dom-parsing.html">DOM Parsing and Serialization</a></cite>, Ms2ger. WHATWG.

<dt id="refsELEMENTTRAVERSAL">[ELEMENTTRAVERSAL]
<dd><cite><a href="http://www.w3.org/TR/ElementTraversal/">Element Traversal Specification</a></cite>, Doug Schepers. W3C.

<dt id="refsHTML">[HTML]
<dd><cite><a href="http://dev.w3.org/html5/spec/">HTML5</a></cite>, Ian Hickson. W3C.

</dl></div>
</div>
<h2 class="no-num" id="acknowledgments">Acknowledgments</h2>

<p>Thanks to

Adrian Bateman,
Brandon Slade,
Cameron McCormack,
Dethe Elza,
David Flanagan,
Glenn Maynard,
Henri Sivonen,
Jacob Rossi,
Jake Verbaten,
James Graham,
Jens Lindstr&ouml;m,
Jo&atilde;o Eiras,
Jonas Sicking,
&#21570;&#24247;&#35946; (Kang-Hao Lu),
Ojan Vafai,
Olli Pettay,
Ryosuke Niwa,
Shiki Okasaka,
Stig Halvorsen, and
Travis Leithead

for their useful comments.

<p>Special thanks to Geoffrey Sneddon and Simon Pieters for first specifying the <a href="#nodes">Nodes</a> section of this specification and their
useful comments.

<p>Special thanks also to Ian Hickson for first specifying some parts of
this specification in HTML and his useful comments.
<a class="informative" href="#refsHTML">[HTML]</a>

<p>Finally, while this specification has been written from scratch, special
thanks should also be extended to the editors of the various specifications
that previously defined the features in this specification. In particular:
<ul>
<li>Arnaud Le Hors
<li>Bj&ouml;rn H&ouml;hrmann
<li>Doug Schepers
<li>Gavin Nicol
<li>Joe Kesselman
<li>Jonathan Robie
<li>Lauren Wood
<li>Mike Champion
<li>Peter Sharpe
<li>Philippe Le H&eacute;garet
<li>Robin Berjon
<li>Steve Byrne
<li>Tom Pixley
<li>Vidur Apparao
</ul>

<!-- vim: set expandtab shiftwidth=1 tabstop=1 textwidth=76 -->