0

I have a raw feed of some text within the body tag of an HTML page. I need to run a function on it to turn it into a Javascript string variable. However, there are literal line breaks in the HTML page (which are obviously not permissible in JS strings).

Here's an example of the source of the page I'm working with:

<html>
<head></head>
<body>
BLDG||0|EOR|

PLNC||0|EOR|

SUBD|Pine Manor|1|EOR|

CITY|Fort Myers|1|EOR|

</body>

jQuery is permissible. How do I turn this all into a Javascript variable while removing the literal line breaks so that the variables work?

2
  • What do you mean literal line breaks aren't permissible in JS strings? What happened to "Line1\nLine2"? Commented Dec 1, 2014 at 21:49
  • 2
    Line breaks are perfectly valid inside a JavaScript variable. They are not valid inside a string constant (unless in escaped form: \n). I'm not exactly sure what you are trying to accomplish. Commented Dec 1, 2014 at 21:49

1 Answer 1

2
var str = document.body.innerHTML.replace(/(\r\n|\n|\r)/gm,"");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.