Spry

Use the Spry Element Selector in a custom function

You can use the Spry Element Selector to manipulate multiple parts of the page at the same time. Use the Element Selector to find all the elements you’re interested in and then use the built-in functions to update the elements.

  1. Link the Element Selector to your Spry page.
    <script src="includes/SpryDOMUtils.js" lang="text/javascript" type="javascript">
  2. Add a function block after the link.
    <script src="includes/SpryDOMUtils.js" lang="text/javascript" type="javascript">
    <script lang="text/javascript" type="javascript">
    function myFunction(){
    }
    </script>
  3. Add the Element Selection function to the function block. In the following example, we’ve added a class to all p tags that occur within a table tag.
    <script src="includes/SpryDOMUtils.js" lang="text/javascript" type="javascript">
    <script lang="text/javascript" type="javascript">
    function myFunction(){
       Spry.$$("table p").addClassName("myClass");
    }
    </script>
  4. Add an event that will execute the function.
    <a href="#" onclick="myFunction();">Click Me</a>