Gustav
Gustav

Reputation: 9

Replace html with html using Javascript

I want to replace a big section of html code (the content on the side) with other html code.

I have used the JavaScript code below:

document.getElementById("content").innerHTML = "";

The thing is that I can't replace html code that got the "" characters in it. Can someone please help me?

I should ad that I´m a beginner with JavaScript and as of now I want to stay away from jQuery.

Upvotes: 0

Views: 62

Answers (1)

Sim1
Sim1

Reputation: 532

try with

document.getElementById("content").innerHTML ='text to be replaced with "" ';

or with

document.getElementById("content").innerHTML ="text to be replaced with \"\"";

or with

document.getElementById("content").innerHTML ='text to be replaced with \'\'';

( \" is the escape sequence for the character " and in javascript you can use either ' or " for the strings)

here the jsfiddle sample

Upvotes: 2

Related Questions