
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
<!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 −
- Related Articles
- How I can change alert message text color using JavaScript?
- How to extract text from a Javascript alert in Selenium with python?
- How to capture the text from Alert Message in Selenium Webdriver?
- How I can replace a JavaScript alert pop up with a fancy alert box?
- How to Line Breaks to JavaScript Alert?
- What is an alert box in JavaScript?
- How to show hyperlinks in JavaScript alert?
- How to edit a JavaScript alert box title?
- How to center the JavaScript alert message box?
- Alert for unsaved changes in form in JavaScript
- JavaScript - Create an alert on clicking an HTML button
- How to provide new line in JavaScript alert box?
- How to design a custom alert box using JavaScript?
- How to show image in alert box using JavaScript?
- How to display JavaScript variable value in alert box?

Advertisements