Wednesday 7 March 2012

How to add click event to Anchor or tag?

Definition: 
In script part you can add click event to Achor or <a></a> tag. With the help of Jquery you can do this. First download the following jquery (jquery-1.4.3.min.js) if you don't have.Second add jquery.

To Add use following code: 
<script src="Jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
(please take care of path where you have save jquery)
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <title>Clcik event</title>
<script src="Jquery/jquery-1.4.3.min.js" type="text/javascript"></script>

    <script type="text/javascript">
       $(document).ready(function(){
             $("a").click(function(event){
             alert("Thanks for visiting!");
          });
        });
    </script>
  </head>
  <body>
    <a href="http://arcreview.blogspot.in/">Arc's Review</a>
  </body>
</html>
Output:
You will see alert box and you press ok button , you will redirect to my blog.

No comments:

Post a Comment