[jquery-dev] Re: Get a selector path from a jquery object

2009-08-02 Thread tres
Just a quick note about it: It is designed to be as specific as possible and works with sibling elements. I just looked at the code and found a couple of unused variables and some parts that could be optimized a bit, but overall, it's pretty fast. I uploaded it on Friday in a bit of a hurry (I wa

[jquery-dev] Re: Get a selector path from a jquery object

2009-08-02 Thread tres
Wrote a plugin for it. http://code.google.com/p/jquery-plugin-dev/source/browse/trunk/jquery.getPath.js On Aug 2, 6:44 am, George wrote: > Yep, that first solution works well. I've used something similar on a > recent project. > (If performance is critical then as well as tweaking the while

[jquery-dev] Re: Get a selector path from a jquery object

2009-08-01 Thread George
Yep, that first solution works well. I've used something similar on a recent project. (If performance is critical then as well as tweaking the while loop I'd be inclined to use .length instead of .size() and to ditch the .toLowerCase() method.) George On Jul 31, 2:34 pm, Julian Aubourg wrote: >

[jquery-dev] Re: Get a selector path from a jquery object

2009-07-31 Thread Julian Aubourg
The issue with simple code like this are siblings. 2009/7/30 DBJDBJ > > Or , maybe : > > function xpath ( selector ) > { > var retval_ = [], xpath_ = "" ; > $(selector).each( function (){ > var e = this ; > do { > xpath_ = "/" + e.tagName + (e.id ? "[...@id=" + e.id +"]" : "")

[jquery-dev] Re: Get a selector path from a jquery object

2009-07-30 Thread DBJDBJ
Or , maybe : function xpath ( selector ) { var retval_ = [], xpath_ = "" ; $(selector).each( function (){ var e = this ; do { xpath_ = "/" + e.tagName + (e.id ? "[...@id=" + e.id +"]" : "") + xpath_ ; e = e.parentNode ; } while ( e.nodeType !== 9 ) retval_.