Share on Google+Share on Google+

Display alert box on clicking link

Advertisement
In this tutorial,html page contains a "a href" link. On clicking this link ,a alert box prompt message "redirecting...." and when we click "Ok" button , it will redirect us to linked page.

Display alert box on clicking link

In this tutorial, we will display alert box to prompt message using jQuery. In the below program , html page contains a "a href" link. On clicking this link ,a alert box prompt message "redirecting...." and when we click "Ok" button , it will redirect us to linked page. Note here, the redirection is due to link not due to alert box or jQuery.

Mylink.html

<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.js">
</script>

<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(event){
alert("Redirecting you to jQuery.com!");
});
});
</script>
</head>
<body>
<a href="http://jquery.com/">
Click here to know about jQuery</a>

</body>
</html>

Description of the program :

$(document).ready(function(){
// Your code here
});

The above code checks whether the page loading is finished and if finished then it executes the code in the block.

The code given below is used to display alert box on clicking link :

$("a").click(function(event){
alert("Redirecting you to jQuery.com!");

OUTPUT :

Download Source Code

Click here to see demo

Advertisements

Advertisement

Posted on: July 24, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.