title: Get unique selector of element in Jquery
body: <p>I want to create something like a recorder whichs tracks all actions of a user. For that, i need to identify elements the user interacts with, so that i can refer to these elements in a later session.</p>
  
  <p>Spoken in pseudo-code, i want to be able to do something like the following</p>
  
  <p>Sample HTML (could be of any complexity):</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
    &lt;div class="example"&gt;
      &lt;p&gt;foo&lt;/p&gt;
      &lt;span&gt;&lt;a href="bar"&gt;bar&lt;/a&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>User clicks on something, like the link. Now i need to identify the clicked element and save its location in the DOM tree for later usage:</p>
  
  <pre><code>(any element).onclick(function() {
    uniqueSelector = $(this).getUniqueSelector();
  })
  </code></pre>
  
  <p>Now, uniqueSelector should be something like (i don't mind if it is xpath or css selector style):</p>
  
  <pre><code>html &gt; body &gt; div.example &gt; span &gt; a
  </code></pre>
  
  <p>This would provide the possibility to save that selector string and use it at a later time, to replay the actions the user made.</p>
  
  <p>How is that possible?</p>
  
  <h1>Update</h1>
  
  <p>Got my answer: <a href="https://stackoverflow.com/questions/2068272/getting-a-jquery-selector-for-an-element">Getting a jQuery selector for an element</a></p>