How to Remove Blank Lines Using Javascript?

Remove Blank Lines by JavaScript, Remove the Blank Lines in a Textarea With JavaScript, Remove Line Breaks Using a Javascript Language, Remove all Blank Lines Using Regular Expressions

 

Friends, what happens when we are programming in any language. So sometimes there is rows or blank space in our programming, whether it is programming of html or programming of php language. By the way, these problems are more so when we are extracting our zip file and uploading it to cpanel’s server. Occur.

Hello Guys so i will tell you today through expertsphp tutorial how you can remove the blank space of your programming language through javascript.

I will try to understand you through Javascript Programming Language, so let’s go.

First of all, you create a textarea type in html and add id space to it.
Then after that you will have to write script type in Javascript Language, I would like to tell you that raplace is a function of Javascript with the help of which you can remove the blank line, let’s see how we can do this.

 

remove-blank-lines-using-javascript.html

<html>
<head>
<title>How to Remove Blank Lines Using Javascript?</title>
</head>
<body>
<textarea id="space">
aaa

bbbb
cccc

ddddddd 
</textarea><button id="remove">Remove blank lines</button>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
jQuery(function ($) {
$("#remove").on("click", function () {
var avalue = $('#space').val();
var newVal = avalue.replace(/^\s*[\r\n]/gm, '');
//var finalResults = newVal.replace("\n", "");
$('#space').val(newVal);
});
})
</script>
</body>
</html>