Javascript Replace() Method Failing?
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 ale
Solution 1:
This will fail because a <p>
cannot contain a <div>
. If you retrieve the inner html of an element with an illegal structure, it will return an unexpected string. So this:
var str = document.getElementById("demo").innerHTML
will return this and only this:
Point: (11, 2) Slope: -
As soon as the browser hits the div
it will stop returning anything past it. Therefore the string you want to replace is never returned, much less replaced.
You should ensure your markup is valid with W3C's validator: https://validator.w3.org/
Post a Comment for "Javascript Replace() Method Failing?"