How to break a line in JavaScript


To break a line in JavaScript we can find space or a special character with the help of regular expression then we can replace the same with </br> tag which will actually break the line of the particular message so the sample code for that is as follows:

 Javascript |  copy code |? 
var div = document.getElementById('message').innerHTML = text.replace(/(\r\n)|(\n)/g,"<br />")

Leave a Comment

Your email address will not be published.