#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    24
    Rep Power
    0

    Take an action when clicking a link


    How can a do to execute a function when clicking a link?

    Something like:


    <p>Link</p>

    <script>
    $("p").click(function () {
    $(this).myFunction();
    });
    </script>


    <script> function myFunction(
    )
    </script>

    Thank you so much
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,169
    Rep Power
    184
    Originally Posted by samuvk
    <p>Link</p>
    That is not a link; that is a paragraph tag. You do a link with an <a> tag. Any way, basically like so:
    Code:
    <script>
    $("a").click(function() {
        myFunction();
    });
    </script>

IMN logo majestic logo threadwatch logo seochat tools logo