I'm trying to use replace()
to get rid of style="border-top-color: green;"
in a chunk of code. The example below shows that it's not working, and I don't understand why.
Doing alert(res);
seems to indicate that the full chunk of code (the HTMl of <p id="demo">
) doesn't seem to be being scanned by replace()
.
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var res = str.replace(' style="border-top-color: green;"', '');
document.getElementById("demo").innerHTML = res;
}
<span id="demo">
Point: (11, 2)
<br>Slope: <span style="position: relative; top: 1px; left: -2px;">-</span>
<div class="fraction_display"><span class="numer_display">12</span><span class="bar_display">/</span><span class="denom_display">7</span>
</div>
<br>
<br>Point-Slope Form: y – 2 = <span style="position: relative; top: 1px; left: -2px;">-</span>
<div class="fraction_display"><span class="numer_display">12</span><span class="bar_display">/</span><span class="denom_display" style="border-top-color: green;">7</span>
</div>(x – 11)
</span>
<button onclick="myFunction()">Replace Fail</button>
Clicking "Replace Fail" will show you that the style="border-top-color: green;"
is still present after it should have been removed. Thoughts?
` cannot contain a `
`, thereby changing the structure you intended to use.
tag as a test, but apparently that was causing the issue. I'll look deeper on my end.
– gtilflm Jun 24 '16 at 16:54. Interesting.......