Open In App

HTML DOM Bold Object

Improve
Improve
Like Article
Like
Save
Share
Report

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: In this example, we will use HTML DOM Bold Object

HTML




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


Output:  

 

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

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Bold Object
    </title>
</head>
 
<body>
    <h1>GeeksForGeeks</h1>
    <h2>DOM Bold Object</h2>
    <button onclick="myGeeks()">
        Submit
    </button>
    <p id="sudo"></p>
 
    <!-- script for Bold Object -->
    <script>
        function myGeeks() {
            let G = document.createElement("B");
            let F =document.createTextNode("GeeksForGeeks");
            G.appendChild(F);
            document.body.appendChild(G);
        }
    </script>
</body>
 
</html>


Output: 

 

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

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


Last Updated : 16 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads