Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM caption align Property

  • Last Updated : 27 Apr, 2020

The HTML DOM caption align Property is used to set or return the value of the align attribute of <caption> element.

Syntax:

  • It returns the caption align property.
    captionobject.align;
  • It sets the caption align property.
    captionobject.align="left | right | center"

Property Values:

  • left: It sets the left-align to caption element.
  • center: It sets the center-align to caption element. It is the default value.
  • right: It sets the right-align to caption element.

Return Value: It returns a string value that represents the alignment of the caption element.

Example 1: This example returns the caption align property.






<!DOCTYPE html>
<html>
  
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;font-size:35px;">
        GeeksForGeeks
    </h1>
    <h2>DOM Caption align Property</h2>
  
    <table>
        <caption id="GFG" align="left">Students</caption>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
    <br>
    <button onclick="myGeeks()">Submit</button>
    <p id="sudo"></p>
    <script>
        function myGeeks() {
            var w = document.getElementById("GFG").align;
            document.getElementById("sudo").innerHTML = w;
        
    </script>
</body>
  
</html>

Output:

  • Before clicking on the Button:
  • After clicking on the Button:

Example 2: This example returns the caption align property.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;font-size:35px;">
        GeeksForGeeks
    </h1>
    <h2>DOM Caption align Property</h2>
  
    <table>
        <caption id="GFG" align="left">
            Students
        </caption>
  
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
    <br>
    <button onclick="myGeeks()">Submit</button>
    <p id="sudo"></p>
  
    <script>
        function myGeeks() {
            var w = document.getElementById(
                    "GFG").align = "right";
  
            document.getElementById(
                    "sudo").innerHTML = w;
        
    </script>
</body>
  
</html>

Output:

  • Before clicking on the Button:
  • After clicking on the Button:

Supported Browsers: The browsers supported by HTML DOM caption align Property are listed below:

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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :