Home javascript How to inscribe a js variable inside a tag when using out.insertAdjacentHTML

How to inscribe a js variable inside a tag when using out.insertAdjacentHTML

Author

Date

Category

For example

var htmlCode = "& lt; div & gt; & lt; span & gt; variable with text & lt; / span & gt; + & lt; span & gt; variable with text 2 & lt; / span & gt; & lt; / div & gt; ";
out.insertAdjacentHTML ('afterBegin', htmlCode);

p.s
this is necessary so that later the div can be flexed and these 2 spans can be aligned with the variables


Answer 1

var a = "Hello";
var b = "world";
var htmlCode = `& lt; div & gt; & lt; span & gt; $ {a} & lt; / span & gt; & lt; span & gt; $ {b} & lt; / span & gt; & lt; / div & gt; `;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions