Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM BR Object

  • Last Updated : 17 Jan, 2019

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.


<!DOCTYPE html>
    <title>br Tag</title>
        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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :