Display functions in javascript

php-programming
Display functions in javascript
30 Nov 2023 62 views
Here are a few popular JavaScript methods and functions for information display.

alert():
Displays a dialog box with a specified message and an OK button.

alert("Hello, World!");
confirm():
Displays a dialog box with a specified message, along with "OK" and "Cancel" buttons. Returns true if the user clicks "OK" and false if the user clicks "Cancel."

var result = confirm("Do you want to proceed?");
prompt():
Displays a dialog box that prompts the user for input. Returns the text entered by the user or null if the user clicks "Cancel."

var userInput = prompt("Please enter your name:", "John Doe");
console.log(), console.warn(), console.error():
Outputs messages to the browser console, commonly used for debugging.
console.log("This is a log message");
console.warn("This is a warning message");
console.error("This is an error message");
document.write():
Writes HTML expressions or JavaScript code to a document. Note that using document.write() after the document has finished loading can overwrite the entire document.

document.write("<h1>Hello, World!</h1>");
innerHTML:
Allows you to get or set the HTML content of an element.

document.getElementById("myElement").innerHTML = "New content";
appendChild():
Appends a node as the last child of a node.

var newElement = document.createElement("p");
var textNode = document.createTextNode("This is a new paragraph.");
newElement.appendChild(textNode);
document.body.appendChild(newElement);
console.clear():
Clears the browser console.

console.clear();