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 >
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
16 Jun, 2023
Like Article
Save Article