Is there a way to take a DOM object and infer a CSS selector that could be used to find that element at a later time.
Example:
<ul class="items">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<script type="text/javascript">
var second = $('.items li:eq(1)');
console.log(get_css_selector(second));
</script>
Where the get_css_selector
would return something similar to .items li:eq(1)
or at least a string that would work to select the element.
Bonus would be if there was a method to generate a CSS selector based on:
<script type="text/javascript">
var third = document.getElementsByTagName('li')[2];
console.log(get_css_selector(third));
</script>