jQuery Data Type How to - Apply line break








Question

We would like to know how to apply line break.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
    var text = "This is line one\nThis is line two\nThis is line three \nThis is the line four";
    var html = text.replace(/\n/g, '<br>');
    console.log(html);<!--from w  w w  .j  av  a 2 s.c  om-->
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: