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?