
- 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.error() Method
The HTML DOM console.error() method is used for writing an error message to the console. This method is very useful for testing and debugging purposes.
Syntax
Following is the syntax for console.error() method −
console.error(console.error(message))
Here, message is a JavaScript string or an object. It is a required parameter value.
Example
Let us see an example for the HTML DOM console.error() method −
<!DOCTYPE html> <html> <body> <h1>console.error() Method</h1> <p>Click the below button to write object as error message on the console</p> <button type="button" onclick="errMessage()">ERROR</button> <script> function errMessage(){ var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"}; console.error(errObj); } </script> <p>Press F12 key to view the error message in the console </p> </body> </html>
Output
This will produce the following output −
On clicking the ERROR button and looking at the console tab in developer tools −
In the above example −
We have first created a button ERROR that will execute the errMessage() function when clicked by the user −
<button type="button" onclick="errMessage()">ERROR</button>
The errMessage() method creates a object with members Message and Value with their respective values. This object is then passed as a parameter to the error() method of the console object. The console.error() method will print the object on the console as an error message −
function errMessage(){ var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"}; console.error(errObj); }
- Related Articles
- 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
- HTML DOM click() method
