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
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
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:
>
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 +"]" : "")
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_.