I have the following code snippet to convert html to javascript, but I seem to be facing an issue with the output when bound to a textarea and I am not able to figure out what the issue could be.
var html_to_text = $('#source').val().replace(' ', ' ').replace(/<[^>]*>/g, '').replace(/(<br>)+/g, '<br>');
The output is correct when displaying on an alert, but, when the same is bound to a text area, there is a lot of white space on it. Could someone help me understand what could be the issue with the above snippet.
I have a working sample of the same at http://jsfiddle.net/technicaliti/uuxDx/
\n
and spaces) in your original HTML, and you're removing a lot of non-whitespace. Which leaves...a lot of whitespace. Also, your first.replace()
call doesn't use a Regular Expression, so it's only going to replace the first occurrence of a (nonexistent)
$('#source').val().replace(/<[^>]*>/g, '').replace(/\n/g, '');