6 points · by arunoda · 14y ago · 13 comments
https://github.com/rcs/jQuery.relativeSelector
Instead of going all the way to the body, this will find a selector that works given the structure of the page.
For instance, a page like:
<body><div id="firstdiv">Target!</div></body>
you can get "#firstdiv" back.For something like
<body><div id="#firstClass"><div class="firstClass"><div>Target!</div></div></div></body>
You can get "#firstClass div:eq(0)".BTW, if the selected element has an "id" attribute (with -by definition- a unique value), what is the point to generate the full selector (cf. "Go to Hell" with "bbg" id in the example)?
for the first one it's kind of a problem. Do you have any sugessions.
For the second one, answer is simple we may have several elements with same id but in different parents. That's why we need something like this.
This is not 100% unique but a innocent try :)
For the second one, specs say that the "id" value must be unique in the entire document [2].
BTW: in reality developers do not adhere to [2] and there is no any browser restrictions for that. So I have to think beyond the spec.
IMO the best approach is still to use $.data('my_element', el)
$.data('my_element', el) works if you everything works on the same page without refreshing the window. But I wanted a way to store the signature on a DB and make it highlighted at some point later.
Just not sure what client-side workflow this kind of tool is used in.