Javascript DOM HTML BR Object get

Introduction

The BR object represents an HTML <br> element.

We can access a <br> element by using getElementById():

var x = document.getElementById("myBR");

Click the button to set the first BR element in the document to display="none".

View in separate window

<!DOCTYPE html>
<html>
<body>
<div>This is a div <br id="myBR"> element with some <br> line breaks.</div>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  w  w  w  .j  av a  2s. c om*/
  var x = document.getElementById("myBR");
  x.style.display = "none";
}
</script>

</body>
</html>



PreviousNext

Related