Patrick Downey
Patrick Downey

Reputation: 965

Is replaceWith supposed to render html as text?

I have inline JavaScript where I try to use jQuery to replace a div with another div when a button has been pressed.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
    attachChangeEvent = setInterval(function(){
        if($("#changeThis").length == 1){
            clearInterval(attachChangeEvent);
            $("#changeText").click(function(){
                $("#changeThis").replaceWith("<div><em>Text Replaced</em></div>");
            });
        }
    }, 100);
</script>
<button id="changeText">click me</button>

<div id="changeThis">Replace this div here</div>

I thought it would replace it so it would look like:

Text Replaced

but instead renders as:

<div>Text Replaced</div>

I've followed several examples, but I don't quite get what I'm doing wrong. I apologize this was asked, but I didn't understand.

The version of jQuery the site I'm using is 1.12.4

Upvotes: 1

Views: 186

Answers (0)

Related Questions