0

I am appending a div and its children in HTML dynamically as below -

var x = 25;
document.getElementById("items").innerHTML += 
        `<div class="details">
          <p>Name</p>
          <p></p>
         </div>`

Requirement : In the second p tag I want to append the value of variable x . How do I do that ? Need help with the syntax.

Thanks!!

codeBug 07
  • 73
  • 7
  • [Duplicate](https://www.google.com/search?q=site%3Astackoverflow.com+js+put+variable+in+string) of [How to interpolate variables in strings in JavaScript, without concatenation?](https://stackoverflow.com/q/3304014/4642212). – Sebastian Simon Oct 21 '20 at 07:32
  • See the [Template literal guide on MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Strings#Template_literals). – Sebastian Simon Oct 21 '20 at 07:42

1 Answers1

0
var x = 25;
document.getElementById("items").innerHTML += 
        `<div class="details">
          <p>Name</p>
          <p>${x}</p>
         </div>`

Try this out!