Skip to content

Determine the XPath of an element with jQuery

License

Notifications You must be signed in to change notification settings

PhrozenByte/jQuery-XPath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jQuery-XPath 1.1

Determine the XPath of an element with jQuery.

Usage

Just download the sourcecode, upload the file to your webspace and load it. Obviously jQuery is required.

<script type="text/javascript" src="js/jquery.xpath.js"></script>

To get the XPath of an element simply call .xpath(). Please note that only the first element in jQuerys list of matched elements is considered. If the given element has an id attribute, the XPath plugin will use it.

$('form input[type=email]').xpath();
// Returns: //*[@id="email"]

If you don't want the id attribute to be considered, pass true as the first parameter.

$('form input[type=email]').xpath(true);
// Returns: /html/body/section/form/div[2]/div/input

Copyright & License

The functionality of jQuery-XPath is pretty much an abstract of Firebugs extension/content/firebug/lib/xpath.js (Version 1.11.1). Copyright remains by the Mozilla Foundation. Accordingly this plugin is licensed under 3-clause BSD. See the LICENSE file for details.