HTML | DOM Figcaption Object

The Figcaption Object in HTML DOM is used to represent the HTML <figcaption> element. The The figcaption element is accessed by getElementById().

Syntax:

document.getElementById("ID");

Where ID represent the element id.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            HTML DOM figcaption Object
        </title
          
        <style
            body { 
                text-align:center; 
            
            h1 { 
                color:green; 
            
        </style
    </head
      
    <body
        <h1>GeeksforGeeks</h1
          
        <h2>DOM Figcaption Object</h2
          
        <figure
            <img src
            alt="gfglogo" style="width:50%"
              
            <figcaption id = "GFG">
                GeeksforGeeks Logo
            </figcaption
        </figure>
          
        <button onclick = "Geeks()">
            Submit
        </button>
          
        <script>
        function Geeks() {
            var gfg = document.getElementById("GFG");
            gfg.style.color = "green";
            gfg.style.fontSize = "20px";
        }
        </script
    </body
</html>                                                     

chevron_right


Output:
Before Click on the button:

After Click on the Button:

Example 2: Figcaption Object can be created by using the document.createElement Method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
    <head
        <title>
            HTML DOM figcaption Object
        </title
        <style
            body { 
                text-align:center; 
            
            h1 { 
                color:green; 
            
        </style
    </head>
      
    <body
        <h1>GeeksforGeeks</h1
        <h2>DOM Figcaption Object</h2
          
        <figure
            <img src
            alt = "gfglogo" style = "width:50%">
        </figure
          
        <button onclick = "Geeks()">
            Submit
        </button>
          
        <!-- script to add figcaption object -->
        <script>
            function Geeks() {
                var x = document.createElement("FIGCAPTION");
                var y = document.createTextNode("GeeksForGeeks Logo")
                x.appendChild(y);
                x.style.color = "green";
                document.body.appendChild(x);
            }
        </script>
    </body
</html>                                            

chevron_right


Before Click on the Button:

After Click on the Button:

Supported Browsers: The browser supported by DOM Figcaption Object are listed below:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.