Skip to content
Related Articles

Related Articles

HTML | DOM BR Object

View Discussion
Improve Article
Save Article
  • Last Updated : 30 Mar, 2022

The DOM BR Object is used to represent the HTML <br> element. The br element is accessed by getElementById().


Where “id” is the ID assigned to the br tag.

  • clear : It is used to Sets or returns the flow of text around floating objects



<!DOCTYPE html>
    <title>HTML | DOM BR Object
        body {
            text-align: center;
        h1 {
            color: green;
    <h2>DOM br Object</h2>
    <!-- br tag is used here -->
        <br id="GFG"> Computer science portal</p>
    <button onclick="myGeeks()">Subnit</button>
        function myGeeks() {
            var w = document.getElementById("GFG");
   = "none";

Before Clicking on Button : 

After Clicking On Button: 

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


<!DOCTYPE html>
        <h2>DOM BR Object</h2>
        <button onclick="Geeks()" style="margin-bottom:20px;">
        <div id="GFG">
            <span>Hello, </span>
            function Geeks() {
                <!-- Get the div element with id="GFG" -->
                var g = document.getElementById("GFG");
                <!-- Get all span elements inside of div. -->
                var f = g.getElementsByTagName("SPAN");
                <!-- Create a loop which will insert a br
                     element before each span element in div,
                     starting from the second span element. -->
                var j;
                for (j = 1; j < f.length; j++) {
                    var w = document.createElement("BR");
                    g.insertBefore(w, f[j]);

Before Clicking on Button: 

After Clicking on Button: 

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

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!