title: Javascript: variable with document.activeElement
body: <p>I want to create a variable to make my code more generic. here is the code I am working on:</p>
  
  <pre><code>eventHandler: function(event) {
      if (event.keyCode == KEY_DOWN) {
          if (this.hasNextSibling(document.activeElement.parentNode)) {
               this.setFocus(document.activeElement.parentNode.nextSibling.firstChild);
           } else {
                this.debug("out");
           }
      }
  },
  setFocus: function(item)
  {
  document.activeElement.tabIndex = "-1";
  item.focus();
  document.activeElement.tabIndex = "0";
  },
  ...
  </code></pre>
  
  <p>The part where I have "document.activeElement.parentNode.nextSibling.firstChild" is the problem. What I want to do first, in order to be able to reuse the code, is to set a variable like this:</p>
  
  <pre><code>var test = document.activeElement.parentNode.nextSibling.firstChild; /*CHANGE HERE*/
  eventHandler: function(event) {
      if (event.keyCode == KEY_DOWN) {
          if (this.hasNextSibling(document.activeElement.parentNode)) {
               this.setFocus(test); /*CHANGE HERE*/
           } else {
                this.debug("out");
           }
      }
  },
  setFocus: function(item)
  {
  document.activeElement.tabIndex = "-1";
  item.focus();
  document.activeElement.tabIndex = "0";
  },
  ...
  </code></pre>
  
  <p>The code does not compile. I tried many different approaches, like method referencing, but nothing seems to work. Does anyone have an idea?</p>
  
  <p>thanks a lot</p>
  
  <p>EDIT:
  here is what I actually would like:</p>
  
  <pre><code>var x = parentNode.nextSibling.firstChild;
  eventHandler: function(event) {
      if (event.keyCode == KEY_DOWN) {
          if (this.hasNextSibling(parent)) {
               this.setFocus(document.activeElement.x);
           } else {
                this.debug("out");
           }
      }
  },
  setFocus: function(item)
  {
  document.activeElement.tabIndex = "-1";
  item.focus();
  document.activeElement.tabIndex = "0";
  },
  </code></pre>
  
  <p>the semantic is not correct. Is there a way I can do that?
  thanks</p>