Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
nate15136y/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */
!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document")...
$( 'body' ).append(`<p>${var}</p>`); -
It depends on _when_ do you want to write that variable to the document.
If you set the variable in the <head> and you want to write it right away in the document, just put this wherever you want to write the variable:
<p><script>document.write(variable);</script></p>
Or if you want to include the <p> tag in the operation:
<script>document.write(`<p>${variable}</p>`);</script>
If you want to write the paragraph when a certain event occurs and not as the page is loading, you can use jQuery as above or go for the longer, vanilla DOM way:
var p = document.createElement('P');
var t = document.createTextNode(variable);
p.appendChild(t);
document.querySelector('body').appendChild(p);
How can I display a JavaScript variable as an paragraph(<p>) in a website
question
html5
help
javascript