Home > Enterprise >  HTML How do I put my variables into the paragraphs as text?
HTML How do I put my variables into the paragraphs as text?

Time:12-07

I have variables labelled $name, $phone, and $totalCost. I want to put them into a paragraph , but I'm not sure how to. Is there a way to break the paragraph just for a few words?

CodePudding user response:

You did not indicate the contents of the paragraph, so this is just a guess.

    let str = `We have created a tag for ${$name} with the phone number of ${$phone}.
    The total cost will be: ${$totalCost}.`;

Write the above as a Temperal Literal statement with JS like:

document.getElementById('elemName').innerHTML = str;

where 'elemName' is the ID value of a paragraph like: <p id='elemName'></p> located somewhere in your HTML page.

CodePudding user response:

You can use the paragraph tags around your text:

<p> $name </p>
  •  Tags:  
  • html
  • Related