0

I want to replace a certain string that contains text between '<' and '>'.

The funny thing is that .replace() works fine on practically any text, but when '<' is included in the string, it doesn't return a filtered string.

Here's some simple code to test it:http://jsfiddle.net/gy0y90g5/

What I've tried:

text only:

var res = str.replace('bijgevoegd>', "");

regex:

var res = str.replace(/bijgevoegd>/g, "");

Because jsfiddle won't display anything that's between < > I've just added one '>' in the example.

Anyone knows whats up with this quircky behaviour?

bdv
  • 1,154
  • 2
  • 19
  • 42

1 Answers1

-1

I made this, i dont know if this is what you want, but here yo go!

<html>
<head>
    <title>STACK OVERFLOW TESTS</title>
</head>
<body>
    <p>Click the button to replace "Microsoft" with "W3Schools" in the paragraph below:</p>

    <p id = 'text'>< Something ></p>

    <input type = 'button' id = 'button' value = 'CLICK ME!'></input>

    <script>
        var button = document.getElementById('button');
        button.addEventListener('click', doTheMagic);

        function doTheMagic(){
            var paragraph = document.getElementById('text');
            paragraph.innerHTML = '< W3Schools >'

        }
    </script>
</body>
</html>
FlokiTheFisherman
  • 224
  • 1
  • 5
  • 13