Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Store HTML Code in JavaScript Variable</title> </head> <body> <div id="wrapper"></div> <script> // Storing HTML code block in a variable var codeBlock = '<div class="content">' + '<h1>This is a heading</h1>' + '<p>This is a paragraph of text.</p>' + '<p><strong>Note:</strong> If you don\'t escape "quotes" properly, it will not work.</p>' + '</div>'; // Inserting the code block to wrapper element document.getElementById("wrapper").innerHTML = codeBlock </script> </body> </html>