Version 8 (modified by amachang, 7 years ago)

--

XPath for Prototype

XPath for Prototype is JavaScript-XPath binding for Prototype.

Release/Download

  • Latest Version
  • If you can use subversion, check out the trunk with:
    svn co http://svn.coderepos.org/share/lang/javascript/javascript-xpath/bindings/prototype/ x4p
    

Requires

How to use

  • Import Prototype JavaScript file.
  • Import JavaScript-XPath JavaScript file (this js file does nothing for browsers which support DOM 3 XPath natively).
  • Import XPath for Prototype JavaScript file.
  • Enjoy with XPath!

Simple Example

<html>
 <head><title>Hello, XPath!</title>

  <!-- import Prototype -->
  <script type="text/javascript" src="prototype.js"></script>
  <!-- import JavaScript-XPath -->
  <script type="text/javascript" src="javascript-xpath.js"></script>
  <!-- import XPath for Prototype -->
  <script type="text/javascript" src="xpath4prototype.js"></script>

  <!-- use XPath -->
  <script type="text/javascript">
// <![CDATA[
window.observe('load', function() {

  $x('//ul/li[@title="xpath"]')[0].insert({top:'Enjoy ', bottom: '!'});

  alert(Element.extend(document.body).xpath('ul/li[1]')[0].innerHTML);
  alert(document.getElementsByXPath('//ul/li[1]')[0].innerHTML);

});
// ]]>
  </script>

 </head>
 <body>
  <h1>Hello, XPath!</h1>
  <ul>
   <li title="xpath">xpath</li>
   <li>dom core</li>
   <li>css selector</li>
  </ul>
 </body>
</html>

Supported Browser

  • IE 6+
  • Safari 2+
  • Firefox 1+
  • Opera 9+

Demo

  • Coming soon.