topical media & game development

talk show tell print

professional-javascript-10-DOMRangeExample9.htm / htm

          <title>DOM Range Example</title>
          <script type="text/javascript">
              function compare() {
                  var oRange1 = document.createRange();
                  var oRange2 = document.createRange();
                  var oP1 = document.getElementById("p1");
                  alert(oRange1.compareBoundaryPoints(Range.START_TO_START, oRange2));  //outputs 0
                  alert(oRange1.compareBoundaryPoints(Range.END_TO_END, oRange2));      //outputs 1;
      <body><p id="p1"><b>Hello</b> World</p>
          <input type="button" value="Compare Ranges" onclick="compare()" />  
          <p><strong>Note:</strong> This example uses DOM ranges and will only work in browsers that support DOM ranges. This example will fail in Internet Explorer.</p>

(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.