HTML | DOM Bdo Object

The DOM Bdo Object is used to represent the HTML <Bdo> element. The Bidirectional element is accessed by getElementById().
Properties: It has a dir attribute which is used to set or return the text direction of an element.
Syntax:

document.getElementById("GFG");

Where “GFG” is the ID assigned to the “bdo” tag.
Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
  
    <head>
        <style>
            h1 {
                color: green;
            }
              
            h2 {
                font-size: 35px;
            }
        </style>
    </head>
  
    <body>
        <h1>GeeksForGeeks</h1>
        <h2>DOM Bdo Object</h2>
        <bdo id="GFG" dir="rtl">
          A Computer science portal for geeks
        </bdo>
        <br>
        <button onclick="myGeeks()">Submit</button>
        <p id="sudo"></p>
  
        <script>
            function myGeeks() {
                var w = document.getElementById("GFG");
                if (w.dir === "rtl") {
                    document.getElementById("sudo").innerHTML =
                        "right to left text direction";
                } else {
                    document.getElementById("sudo").innerHTML =
                        " left to right text direction.";
                }
            }
        </script>
  
    </body>
  
</html>

chevron_right


Output:
Before Clicking On Button:

After Clicking on Button:

Example-2: Bdo Object can be created by using the “document.createElement method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
  
    <head>
        <style>
            h1 {
                color: green;
            }
              
            h2 {
                font-size: 35px;
            }
        </style>
    </head>
  
    <body>
        <h1>GeeksForGeeks</h1>
        <h2>DOM Bdo Object</h2>
        <button onclick="myGeeks()">Submit</button>
  
        <script>
            function myGeeks() {
                var g = document.createElement("BDO");
                var f = document.createTextNode("GeeksForGeeks.");
                g.setAttribute("dir", "rtl");
                g.appendChild(f);
                document.body.appendChild(g);
            }
        </script>
  
    </body>
  
</html>

chevron_right


Output:
Before Clicking on Button:

After Clicking on Button:

Supported Browsers: The browser supported by DOM Bdo 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.