I need to replace all these tags </script> with these tags </script>
Before: -> <script>..code..</script> <script>..code..</script>
After: ---> <script>..code..<\/script> <script>..code..<\/script>
But this does not work:
function myReplace(){
var X = document.getElementById("demo").innerText;
var Y = X.replace(/</script>/ig, '<\/script>');
document.getElementById("demo").innerText = Y;
}
Here's a related post for a better understanding
/</script>/igisn't a valid regex. The/inside needs escaping. By the way, why are you doing this? Do you want to have a bunch of unclosed script tags?innerHTMLand set usingtextContentorinnerTextlike this.