title: How to get the xpath by clicking an html element
body: <p>I am quite new to programming and have to generate a Xpath on clicking an html element.
  for example :if i have clicked on text box of username then it should give me the xpath like
  html/head/body/tr[1]/table[2]..... etc etc. The main thing is i can not use firebug as my application is thoroughly goin to run on IE. I have seen lot of fxn to get xpath and tried to integrate it but i am not getting the return value. A simple code snippet where i used jquery click() function to retrieve the value is not working.The thing is i am unable to pass the html element in the function.The xpath function i have taken from this site only. My code is below. </p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;click demo&lt;/title&gt;
  &lt;style&gt; 
  p
  { 
     color: red;    
     margin: 5px;
     cursor: pointer; 
  }  
  p:hover
   { 
     background: yellow; 
   }
  &lt;/style&gt; 
  &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt; 
  &lt;p id ="test"&gt;First Paragraph&lt;/p&gt;
  &lt;p&gt;Second Paragraph&lt;/p&gt;
  &lt;p&gt;Yet one more Paragraph&lt;/p&gt;
  &lt;script&gt;
  
  $( "#test" ).click(function() { var value= $(this).getXPath();
  alert(value) });
  
  function getXPath( element )
  {
  var val=element.value;
  alert("val="+val);
      var xpath = '';
      for ( ; element &amp;&amp; element.nodeType == 1; element = element.parentNode )
      {
          alert(element);
          var id = $(element.parentNode).children(element.tagName).index(element) + 1;
          id &gt; 1 ? (id = '[' + id + ']') : (id = '');
          xpath = '/' + element.tagName.toLowerCase() + id + xpath;
      }
      return xpath;
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>