Explain JavaScript text alert


The JavaScript alert() function is used to display a popup message to the user.

Following is the code for the JavaScript alert() function −

Example

 Live Demo

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
</style>
</head>
<body>
<h1>Javascript text alert</h1>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to trigger the alert popup</h3>
<script>
   let BtnEle = document.querySelector(".Btn");
   BtnEle.addEventListener("click", () => {
      alert("You pressed the button");
   });
</script>
</body>
</html>

Output

The above code will produce the following output −

On clicking the ‘CLICK HERE’ button −

Updated on: 21-Jul-2020

133 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements