Tutorial by Examples

DOM stands for Document Object Model. It is an object-oriented representation of structured documents like XML and HTML. Setting the textContent property of an Element is one way to output text on a web page. For example, consider the following HTML tag: <p id="paragraph"></p&g...
Introduction All modern web browsers, NodeJs as well as almost every other JavaScript environments support writing messages to a console using a suite of logging methods. The most common of these methods is console.log(). In a browser environment, the console.log() function is predominantly used f...
The alert method displays a visual alert box on screen. The alert method parameter is displayed to the user in plain text: window.alert(message); Because window is the global object, you can call also use the following shorthand: alert(message); So what does window.alert() do? Well, let's ta...
An easy way to get an input from a user is by using the prompt() method. Syntax prompt(text, [default]); text: The text displayed in the prompt box. default: A default value for the input field (optional). Examples var age = prompt("How old are you?"); console.log(age); // Pri...
Using canvas elements HTML provides the canvas element for building raster-based images. First build a canvas for holding image pixel information. var canvas = document.createElement('canvas'); canvas.width = 500; canvas.height = 250; Then select a context for the canvas, in this case two-di...
The window.confirm() method displays a modal dialog with an optional message and two buttons, OK and Cancel. Now, let's take the following example: result = window.confirm(message); Here, message is the optional string to be displayed in the dialog and result is a boolean value indicating wheth...

Page 1 of 1