WordPress.org

Support

Support » Plugins and Hacks » Add javascript to all links in post/page

Add javascript to all links in post/page

  • Hello all,

    I’m developing a site for a client and what he wants requires all links in the posts to have javascript attached to it automatically.

    It goes something like this. Let’s say in the post he creates a link with the name of LINKNAME. Here’s what needs to happen automatically:

    <a href="URL" onMouseOver="setReadOut(LINKNAME)">LINKNAME</a>

    Where the javascript gets added automatically when he publishes the page and the LINKNAME becomes a variable passed to the javascript.

    Any takers?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Jquery would be perfect, if your not familiar with it check it out.

    <script type="text/javascript">
    $(document).ready(function() { // run when the document is loaded
        $("a").click(function () { // bind a click function to all links
        	linkname = $(this).val(); // get the link name
            setReadOut(linkname); // run your function
          });
     });
    </script>

    jquery.com

    quick question on this:

    First, I modified it to .mouseenter instead of .click

    Secondly, setReadOut() needs to take strings enclosed in ‘ ‘ so it would have to return a function like setReadOut(‘link name’)

    It seems to not be working for this?

    So i just tested and with hyperlinks and instead of

    linkname = $(this).val();

    should be

    linkname = $(this).text();

    To take the text of the hyperlink.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add javascript to all links in post/page’ is closed to new replies.
Skip to toolbar