jQuery alert()

This jQuery tutorials teaches you abut the jQuery alert ans how alert box works in jQuery. The given example uses alert boxes to provide information on run time.

jQuery alert()


jQuery alert()

In this jQuery tutorial we will discuss how an alert box works in jQuery. Moreover, this tutorial will discuss in details about alert box in jQuery.

In the given application here, alert boxes have been used to provide information at run time basis. Through this information, the user of the application gets help to perform the tasks further with more information at runtime. Alert box can be popped up after an event happens as for click event or after the completion of a line of code execution. click() function in jQuery is used to bind the click event, JavaScript event.

Advertisement

Example

Here, we will explain jQuery alert with the help of a simple example, ehich would help you understand the concept easily. In this example, we have shown about how an alert box can display information. This example displays an alert box after clicking a button, which generates the click event. When a user executes this example and click on the button, this displays the alert box.

jQueryAlertExample.html

<!DOCTYPE html>
<html>
<head>
<title>jQuery Alert Example</title>
<style>
p { color:red; margin:5px; cursor:pointer; }
p:hover { background:yellow; }
</style>
<script type="text/javascript" src="jquery-1.9.1.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
$("#b1").click(function(){
alert("jQuery alert box example !");
});
});
</script>
<body>
<p>Click on button</p>
<button id="b1">Click Here</button>
</body>
</html>