0

This question is related to Javascript replace() method failing?, but I thought it was different enough to be it's own question.

I'm trying to use replace() to get rid of style="border-top-color: green;" in a chunk of code. The example below represents the type of input I'll be getting. It seems that it's not working in implementation because of the javascript error.

function myFunction() {
  var str = '
    y + 7 = <span style="position: relative; top: 1px; left: -2px;">-</span><div class="fraction_display"><span class="numer_display">2</span><span class="bar_display">/</span><span class="denom_display" style="border-top-color: green;">25</span></div>(x – 11)
  
  
  ';
  var res = str.replace(' style="border-top-color: green;"', '');
  document.getElementById("demo").innerHTML = res;
}
<p id="demo">Result</p>

  <button onclick="myFunction()">Replace Fail</button>

Any way to solve the issue of line breaks, spaces, etc. not playing nicely as a string?

Community
  • 1
  • 1
gtilflm
  • 1,389
  • 1
  • 21
  • 51
  • 1
    Use `\\` at the end of each line to store multi-line strings. – Spencer Wieczorek Jun 24 '16 at 17:21
  • How is this question duplicate? I don't see connection at all – Luka Jun 24 '16 at 17:25
  • @SpencerWieczorek: Not sure how to do that. Have a brief example by chance? – gtilflm Jun 24 '16 at 17:26
  • @gtilflm Yeah I was about to post an answer but the question was closed. At each part of the end of each line in your string add \. [Here is a fiddle showing that](https://jsfiddle.net/fycg0kos/1/). – Spencer Wieczorek Jun 24 '16 at 17:27
  • @Luka Because the solution to this problem is to store the string of many lines. Different questions but they have the same solution. – Spencer Wieczorek Jun 24 '16 at 17:31
  • It seams to me that this is the string that is input in the system, which OP wants to manipulate, and it is not the string that he/she created, as it says "The example below represents the type of input I'll be getting". Maybe I misunderstood the question. – Luka Jun 24 '16 at 17:53

0 Answers0