
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM console.clear() Method
The HTML DOM console.clear() method is used to clear the console. The console.clear() method will also write “Console was cleared” message in the console and clears all the previous console content. This method is fully supported by all the browsers.
Syntax
Following is the syntax for console.clear() method −
console.clear()
Example
Let us see an example for the HTML DOM console.clear() method −
<!DOCTYPE html> <html> <body> <h1>JavaScript console.clear() Method</h1> <p>Press F12 on the keyboard to see the message on your console</p> console.log("TEXT has been printed on the console!"); <p>Click the below button to clear the console</p> <button onclick="clearConsole()">CLEAR</button> <script> function clearConsole() { console.clear(); } </script> </body> </html>
Output
This will produce the following output −
Console −
On clicking the CLEAR button −
In the above example −
We have written some message to the console using the console.log() method −
console.log("TEXT has been printed on the console!");
We have then created a button CLEAR that will execute the clearConsole() method −
<button onclick="clearConsole()">CLEAR</button>
The clearConsole() method calls the clear() function on the console object. This clears the console and writes “Console was cleared” on the console.
function clearConsole() { console.clear(); }
- Related Articles
- Console.Clear Method in C#
- HTML DOM addEventListener() Method
- HTML DOM normalize( ) Method
- HTML DOM write() Method
- HTML DOM writeln() Method
- HTML DOM insertAdjacentElement( ) Method
- HTML DOM insertAdjacentHTML( ) Method
- HTML DOM insertAdjacentText( ) Method
- HTML DOM insertBefore( ) Method
- HTML DOM isDefaultNamespace( ) Method
- HTML DOM isEqualNode( ) Method
- HTML DOM isSameNode( ) Method
- HTML DOM item( ) Method
- HTML DOM appendChild() Method
- HTML DOM blur() Method
