title: JavaScript find li index within ul
body: <p>I'm trying to find the index of my list item by id in Javascript. For example I have  list of 5 items and given an element I want to figure out which position it is in the list. Below is the code that I hope to build on.</p>
  
  <p>It's using an onclick handler to find the element, which is working, I then just need to figure out the position of the element in the list 'squareList' in some way. </p>
  
  <pre><code>window.onload=function(){
      function getEventTarget(e){
          var e=e || window.event;
          return e.target || e.srcElement;
      }
  
      function selectFunction(e){
          var target=getEventTarget(e);
          alert(target.id);
      }
  
      var squareList=document.getElementById('squareList');
      squareList.onclick=function(e){
          selectFunction(e);
      }
  }
  </code></pre>