Mega Code Archive

 
Categories / JavaScript DHTML / HTML
 

Using Anchors to Navigate Through a Page

<html>  <head>  <title>document.anchors Property</title>  <script type="text/javascript">  function goNextAnchor(where) {      window.location.hash = where;  }  function addEvent(elem, evtType, func) {      if (elem.addEventListener) {          elem.addEventListener(evtType, func, false);      } else if (elem.attachEvent) {          elem.attachEvent("on" + evtType, func);      } else {          elem["on" + evtType] = func;      }  }  addEvent(window, "load", function() {      addEvent(document.getElementById("next1"), "click", function(evt) {goNextAnchor("sec1")});      addEvent(document.getElementById("next4"), "click", function(evt) {goNextAnchor("start")});  });  </script>  </head>  <body>  <a id="start" name="start">Top</a> <form>      <input type="button" id="next1" name="next" value="NEXT" />  </form>  <a id="sec1" name="sec1">Section 1</a> <form>      <input type="button" id="next4" name="next" value="BACK TO TOP" />  </form>  </body>  </html>