Reverse selector engineering with mootools

css javascript mootools selectors

What if you need to get the css selector which targets a DOM element given the element itself?

This is the case for example when you want to store some added information over an element and show it after recharging the page. In this case you may store the information in the local storage object together with the path to the element, in other words you must be able to store the element position inside the DOM

In this scenario for example you have the user choosing the element with a click event, ask him for input some information and then store the information and the path to the element, so that when recharging the page the information can be tied to the element selected.

To get this you can use the following js function I wrote. Only some requirements here:

  • the function requires the mootools selector engine
  • the function works in browsers which support the nth-of-type pseudo-selector

Here comes the function

Subscribe to abidibo.net!

If you want to stay up to date with new contents published on this blog, then just enter your email address, and you will receive blog updates! You can set you preferences and decide to receive emails only when articles are posted regarding a precise topic.

I promise, you'll never receive spam or advertising of any kind from this subscription, just content updates.

Subscribe to this blog

Comments are welcome!

blog comments powered by Disqus

Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!