Comments on: XPath Bookmark Bookmarklet http://localhost/wp/2009/11/xpath-bookmark-bookmarklet/ this title probably isn't very original Fri, 30 May 2014 19:32:06 +0000 hourly 1 By: luben http://localhost/wp/2009/11/xpath-bookmark-bookmarklet/comment-page-1/#comment-15967 Thu, 14 Oct 2010 10:39:03 +0000 Nice (and useful) bookmarklet but, once you have the url updated, how do you use it?
(I can’t use it as a valid link)
Thk you

By: Steve http://localhost/wp/2009/11/xpath-bookmark-bookmarklet/comment-page-1/#comment-15900 Wed, 19 May 2010 05:46:28 +0000 I came across your script, and converted it to a jQuery plugin for a specific need that I had. Here’s the script:

(function($){$.fn.xpath=function(){ var el=this;for(var e=””,c=$_(el)[0];c&&c.nodeType==1;c=c.parentNode){var b=$_(c.parentNode).children(c.tagName).index(c)+1;b>1?(b=”["+b+"]“):(b=””);e=”/”+c.tagName.toLowerCase()+b+e;}return e;};})(jQuery);

Using this, I can reference the xPath of any element on a page by calling $(“#SomeElement”).xpath();

Thanks :)