Is it possible to store a jQuery selector for a unique dom object and re-use it after a page reload?
$('body')
.on('click', '*', function(e) {
e.stopPropagation();
var whatIwanttostore = $(this);
});
I considered navigating up the DOM, storing the index of the element and constructing a selector that looks like $('div:nth-child(1) div:nth-child(2) div:nth-child(4)') or perhaps doing that but only going up as far as the closest element with an id but that doesn’t seem like the best way of doing it.
What you want to store is a jQuery object, not a selector, and this is not possible. A page is stateless and knows (almost) nothing about the previous page.
If you wanted to store the selector (for example ‘div:nth-child(1) div:nth-child(2) div:nth-child(4)’), you could use cookies, or sessionStorage/localStorage in modern browsers.