How to convert line breaks to br in jQuery ?

How to convert line breaks to br in jQuery ?

In this post we will give you information about How to convert line breaks to br in jQuery ?. Hear we will give you detail about How to convert line breaks to br in jQuery ?And how to use it also give you demo for it if it is necessary.

If you are use textarea and you want to like break into br(n) so that way we can give format as user insert, but if you are working on php then you can easily doing with nl3br() through, but if you are using in jquery or javascript then you have to first declare that. i did give full example of jquery textarea line breaks as under.

<body>

<textarea ></textarea>

<script>

var text_content = <?php echo $content ?>;

function nl2br (str, is_xhtml) {

var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br/>' : '<br>';

return (str + '').replace(/([^>rn]?)(rn|nr|r|n)/g, '$1'+ breakTag +'$2');

}

$(".textareac").val(nl2br(text_content));

</script>

<body/>

Try this..

Hope this code and post will helped you for implement How to convert line breaks to br in jQuery ?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

2  +    =  3

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US