How to make trailing <br> tag in <div> behave like trailing line break in <textarea>?

Viewed 43

In following snippet, I would like trailing <br> inside of <div> to behave like trailing line break in <textarea> so both <div> and <textarea> have same scrollHeight.

const div = document.getElementById("div")
const textarea = document.getElementById("textarea")
console.log(div.scrollHeight, textarea.scrollHeight)
div, textarea {
  background-color: grey;
  border: 0;
  font-family: monospace;
  height: 24px;
  margin: 0;
  overflow: scroll;
  padding: 0;
  width: 100%;
}
<div id="div">
foo<br>
bar<br>
</div>
<br>
<textarea id="textarea">foo
bar
</textarea>

0 Answers
Related