HTML | DOM Bold Object

The DOM Bold Object is used to represent the HTML <b> element. The bold element is accessed by getElementById().
Syntax:

document.getElementById("ID");

Where “id” is the ID assigned to the “b” tag.
Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM Bold Object
    </title>
  
    <script>
        function myGeeks() {
            var b = document.getElementById("GFG");
            b.style.backgroundColor = "red";
        }
    </script>
</head>
  
<body>
    <b></b>
    <h1 id="GFG">GeeksForGeeks</h1></b>
    <h2 style="font-size:35px;">DOM Bold Object</h2>
    <BR>
    <button onclick="myGeeks()">
        Submit
    </button>
  
    <p id="geeks"></p>
</body>
  
</html>

chevron_right


Output:
Before Clicking On the Button:

After Clicking on Button:

Example-2: Bold 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 Bold Object
    </title>
  
    <!-- script for  Bold Object -->
    <script>
        function myGeeks() {
            var G = document.createElement("B");
            var F = 
            document.createTextNode("GeeksForGeeks");
            G.appendChild(F);
            document.body.appendChild(G);
        }
    </script>
</head>
  
<body>
    <H1>GeeksForGeeks</H1>
    <h2>DOM Bold Object</h2>
  
    <button onclick="myGeeks()">
        Submit
    </button>
  
    <p id="sudo"></p>
  
</body>
  
</html>                  

chevron_right


Output:
Before Clicking on Button:

After Clicking on Button:

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