I am writing an application where I store relative references to elements as a CSS selector suitable for navigating to querySelector. When I want to keep a relative reference to the "base" element, I would like to have a selector that will return the same element.
What is an identifier selector for the querySelector method for Element , as defined in level 1 APIs , which satisfies the following
var identitySelector = "<this is the selector I want to know>" for (int i = 0; i < document.all.length; i++) { var elem = document.all[i]; if (elem !== elem.querySelector(identitySelector)) { throw identitySelector + " is not the identity selector"; } }
Update:
Since this selector is not available, I am going to wrap my querySelector call with a function that returns a context element if the selector is equal to the :root pseudo- :root .
var identitySelector = ":root" var querySelectorProxy = function(elem, selector) { return selector === ':root' ? elem: elem.querySelector(identitySelector); } for (int i = 0; i < document.all.length; i++) { var elem = document.all[i]; if (elem !== querySelectorProxy(elem, selector)) { throw identitySelector + " is not the identity selector"; } }
source share