Javascript Reference - HTML DOM BR Object








The BR object represents an HTML <br> element.

BR Object Properties

Property Description
clear Sets or gets the flow of text around floating objects

The clear property is not supported in HTML5.

We can use style.clear instead.

Standard Properties and Events

The BR object supports the standard properties and events.

Example

The following code shows how to get a <br> element by using getElementsByTagName():


<!DOCTYPE html>
<html>
<body>
<div>test<br/> test <br/> test</div>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--  w w  w .j ava2s  . c om-->
    var x = document.getElementsByTagName("BR")[0];
    x.style.display = "none";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <br> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<div id="myDIV">
  <span>test</span><span>test</span><span>test</span>
</div><!--   w ww  .j a v a 2 s.co  m-->
<script>
function myFunction() {
    var div = document.getElementById("myDIV"); 
    var spans = div.getElementsByTagName("SPAN");  
    var i;
    for (i = 1; i < spans.length; i++) {
        var newElem = document.createElement("BR");
        div.insertBefore(newElem, spans[i]);
    }
}
</script>
</body>
</html>

The code above is rendered as follows: