Home Tutorial Jquery Display alert box on clicking link

 
 

Display alert box on clicking link
Posted on: July 24, 2010 at 12:00 AM
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

Related Tags for Display alert box on clicking link:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.