Related Articles

Related Articles

HTML | DOM console.group() Method
  • Difficulty Level : Basic
  • Last Updated : 23 Jul, 2019

The console.group() method in HTML is used to create a group of messages in the console. It indicates the start of a message group and all the messages written after calling the console.group() method will write inside the message group. The label is sent as an optional parameter to the console.group() method.

Syntax:

console.group( label )

Parameters: This method accepts single parameter label which is optional and used to specify the label for the group.

Below program illustrates the console.group() method in HTML:

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head
        <title>DOM console.group() Method</title
        <style
            h1 { 
                color:green; 
            
            h2 {
                font-family: Impact;
            }
            body { 
                text-align:center; 
            
        </style
    </head>
    <body>
        <h1>GeeksforGeeks</h1
        <h2>DOM console.group() Method</h2
  
        <p>
         To view the message in the console
         press the F12 key on your keyboard.
        </p>
        <script>
            console.log("GeeksforGeeks offers the following courses :");
            console.group();
            console.log("1. fork python");
            console.log("2. fork cpp");
            console.log("3. fork java");
            console.log("4. Interview preparation");
        </script>
    </body>
</html>                    

chevron_right


Output:

Console View:

Example 2: Using the label parameter with the console.group() method

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head
        <title>DOM console.group() Method</title
        <style
            h1 { 
                color:green; 
            
            h2 {
                font-family: Impact;
            }
            body { 
                text-align:center; 
            
        </style
    </head>
    <body>
        <h1>GeeksforGeeks</h1
        <h2>DOM console.group() Method</h2
        <p>
         To view the message in the console 
         press the F12 key on your keyboard.
        </p>
        <script>
            console.log("GeeksforGeeks offers the following courses:");
            console.group("Courses");
            console.log("1. fork python");
            console.log("2. fork cpp");
            console.log("3. fork java");
            console.log("4. Interview preparation");
        </script>
    </body>
</html>                    

chevron_right


Output:

Console View:

Supported Browsers: The browsers supported by console.group() method are listed below:

  • Google Chrome
  • Internet Explorer 11.0
  • Firefox 4.0
  • Opera
  • Safari 4.0

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :