Open In App

HTML DOM Emphasized Object

Last Updated : 01 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML DOM Emphasized object represents the <em> element, used to emphasize text, typically rendering it in italics. It can be accessed and manipulated through JavaScript to alter its content or styling.

Syntax:

document.getElementById("ID");

Example: Clicking the “Submit” button changes the emphasized text color to red and increases its font size to 29px.

html
<!DOCTYPE html>
<html>

<head>
    <title>DOM Emphasized Object</title>
</head>

<body>
    <h2>DOM Emphasized Object</h2>
    <!--Text in Italics-->
    <p>Hello GeeksforGeeks</p>
    <!--Text in Emphasize-->
    <p><em id="GFG">Hello GeeksforGeeks</em></p>

    <button onclick="mygeeks()">
        Submit
    </button>

    <script>
        function mygeeks() {
            let gfg = document.getElementById("GFG");
            gfg.style.color = "red";
            gfg.style.fontSize = "29px";
        }
    </script>
</body>

</html>

Output:

em1

em

Example-2 : Give below example create em element upon clicking the button.

html
<!DOCTYPE html>
<html>

<head>
    <title>DOM Emphasized Object</title>
</head>

<body>
    <h2>DOM Emphasized Object</h2>

    <!--Text in Paragraph-->
    <p>Hello GeeksforGeeks</p>

    <button onclick="mygeeks()">
        Submit
    </button>

    <br><br>

    <script>
        function mygeeks() {
            let gfg = document.createElement("em");
            let text =
                document.createTextNode("Hello GeeksForGeeks");
            gfg.appendChild(text);

            document.body.appendChild(gfg);
        }
    </script>
</body>

</html>

Output:

em2

create em element

Supported Browsers:

The browser supported by DOM Emphasized Object are listed below:

  • Google Chrome
  • Firefox
  • Opera
  • Safari

Next Article
Article Tags :

Similar Reads